mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
docs: Fix custom storage sync event (#55753)
* docs: fix unexpected storage logic * Update .dumi/hooks/useLocalStorage.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: 遇见同学 <1875694521@qq.com> --------- Signed-off-by: 遇见同学 <1875694521@qq.com> Co-authored-by: 遇见同学 <1875694521@qq.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -83,9 +83,15 @@ const useLocalStorage = <T>(key: string, options: Options<T> = {}) => {
|
||||
[key],
|
||||
);
|
||||
|
||||
const shouldSyncCustomEvent = (ev: CustomEvent<{ key: string; storageArea: Storage }>) => {
|
||||
return ev?.detail?.key === key && ev?.detail?.storageArea === storage;
|
||||
};
|
||||
|
||||
const onCustomStorage = useCallback(
|
||||
(event: Event) => {
|
||||
if (shouldSync(event as StorageEvent)) {
|
||||
const customEvent = event as CustomEvent;
|
||||
|
||||
if (shouldSyncCustomEvent(customEvent)) {
|
||||
setState(getStoredValue());
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user