fix: SF squad never knows best
This commit is contained in:
parent
097c9328ec
commit
842244e289
|
@ -3,13 +3,15 @@ import {
|
||||||
useState,
|
useState,
|
||||||
} from '@flecks/react';
|
} from '@flecks/react';
|
||||||
|
|
||||||
|
const useBrowserLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : () => {};
|
||||||
|
|
||||||
const useLocalStorage = (key, defaultValue) => {
|
const useLocalStorage = (key, defaultValue) => {
|
||||||
const [value, setValue] = useState(defaultValue);
|
const [value, setValue] = useState(defaultValue);
|
||||||
useLayoutEffect(() => {
|
useBrowserLayoutEffect(() => {
|
||||||
setValue(JSON.parse(window.localStorage.getItem(key) || JSON.stringify(defaultValue)));
|
setValue(JSON.parse(window.localStorage.getItem(key) || JSON.stringify(defaultValue)));
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [key]);
|
}, [key]);
|
||||||
useLayoutEffect(() => {
|
useBrowserLayoutEffect(() => {
|
||||||
window.localStorage.setItem(key, JSON.stringify(value));
|
window.localStorage.setItem(key, JSON.stringify(value));
|
||||||
}, [key, value]);
|
}, [key, value]);
|
||||||
return [value, setValue];
|
return [value, setValue];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user