🐛 Corrige un avertissement relatif au stockage local

pull/1803/head
Maxime Quandalle 2021-10-26 17:33:46 +02:00
parent 55fc3a2bc3
commit 2ded743e1c
1 changed files with 3 additions and 2 deletions

View File

@ -3,12 +3,13 @@ import safeLocalStorage from '../../storage/safeLocalStorage'
export const getInitialState = (key: string) => {
const value = safeLocalStorage.getItem(key)
if (!value) {
if (value === 'undefined' || !value) {
return
}
try {
return JSON.parse(value)
} catch (e) {
// eslint-disable-next-line no-console
console.warn(e)
return null
}
@ -19,7 +20,7 @@ export const useSafeLocaleStorage = (key: string, state: any) => {
if (key) {
safeLocalStorage.setItem(key, JSON.stringify(state))
}
}, [state])
}, [key, state])
}
export const usePersistingState = <S>(key: string, defaultState?: any) => {