Skip to content

Commit

Permalink
Merge branch 'master' of github.com-rtivital:mantinedev/mantine
Browse files Browse the repository at this point in the history
  • Loading branch information
rtivital committed Apr 4, 2024
2 parents fcec0e3 + 5448d39 commit 4c9a875
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function createStorage<T>(type: StorageType, hookName: string) {
const storageValue = getItem(key);
return storageValue !== null ? deserialize(storageValue) : (defaultValue as T);
},
[key, deserialize, defaultValue]
[key, defaultValue]
);

const [value, setValue] = useState<T>(readStorageValue(getInitialValueInEffect));
Expand All @@ -122,13 +122,13 @@ export function createStorage<T>(type: StorageType, hookName: string) {
setValue(val);
}
},
[key, serialize]
[key]
);

const removeStorageValue = useCallback(() => {
removeItem(key);
window.dispatchEvent(new CustomEvent(eventName, { detail: { key, value: defaultValue } }));
}, [defaultValue, key]);
}, []);

useWindowEvent('storage', (event) => {
if (event.storageArea === window[type] && event.key === key) {
Expand All @@ -151,7 +151,7 @@ export function createStorage<T>(type: StorageType, hookName: string) {
useEffect(() => {
const val = readStorageValue();
val !== undefined && setStorageValue(val);
}, [readStorageValue, setStorageValue]);
}, []);

return [value === undefined ? defaultValue : value, setStorageValue, removeStorageValue] as [
T,
Expand Down

0 comments on commit 4c9a875

Please sign in to comment.