diff options
Diffstat (limited to 'modern/src/common/usePersistedState.js')
-rw-r--r-- | modern/src/common/usePersistedState.js | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/modern/src/common/usePersistedState.js b/modern/src/common/usePersistedState.js index 0a6627c..a3a60d7 100644 --- a/modern/src/common/usePersistedState.js +++ b/modern/src/common/usePersistedState.js @@ -1,13 +1,13 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; -export default usePersistedState = (key, defaultValue) => { +export const usePersistedState = (key, defaultValue) => { const [value, setValue] = useState(() => { const stickyValue = window.localStorage.getItem(key); return stickyValue ? JSON.parse(stickyValue) : defaultValue; }); - React.useEffect(() => { + useEffect(() => { window.localStorage.setItem(key, JSON.stringify(value)); }, [key, value]); |