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:
SocietyNiu
2025-11-18 03:12:05 +01:00
committed by GitHub
parent ebcfbb1145
commit 7aabe2a4fa

View File

@@ -83,9 +83,15 @@ const useLocalStorage = <T>(key: string, options: Options<T> = {}) => {
[key], [key],
); );
const shouldSyncCustomEvent = (ev: CustomEvent<{ key: string; storageArea: Storage }>) => {
return ev?.detail?.key === key && ev?.detail?.storageArea === storage;
};
const onCustomStorage = useCallback( const onCustomStorage = useCallback(
(event: Event) => { (event: Event) => {
if (shouldSync(event as StorageEvent)) { const customEvent = event as CustomEvent;
if (shouldSyncCustomEvent(customEvent)) {
setState(getStoredValue()); setState(getStoredValue());
} }
}, },