diff options
Diffstat (limited to 'modern/src/common/usePersistedState.js')
-rw-r--r-- | modern/src/common/usePersistedState.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modern/src/common/usePersistedState.js b/modern/src/common/usePersistedState.js index 0a7a990e..8bc4401f 100644 --- a/modern/src/common/usePersistedState.js +++ b/modern/src/common/usePersistedState.js @@ -1,5 +1,9 @@ import { useEffect, useState } from 'react'; +export const savePersistedState = (key, value) => { + window.localStorage.setItem(key, JSON.stringify(value)); +}; + export default (key, defaultValue) => { const [value, setValue] = useState(() => { const stickyValue = window.localStorage.getItem(key); @@ -7,7 +11,7 @@ export default (key, defaultValue) => { }); useEffect(() => { - window.localStorage.setItem(key, JSON.stringify(value)); + savePersistedState(key, value); }, [key, value]); return [value, setValue]; |