parent
0e68373893
commit
6b19ad2ec3
@ -1,4 +1,4 @@ |
|||||||
export const querieKeys = { |
export const querieKeys = { |
||||||
matchScore: 'matchScore', |
|
||||||
liveMatchScores: 'liveMatchScores', |
liveMatchScores: 'liveMatchScores', |
||||||
|
matchScore: 'matchScore', |
||||||
} |
} |
||||||
|
|||||||
@ -1,29 +0,0 @@ |
|||||||
import { useState } from 'react' |
|
||||||
|
|
||||||
export const useLocalStorage = (keyName: string, defaultValue?: any) => { |
|
||||||
const [storedValue, setStoredValue] = useState(() => { |
|
||||||
try { |
|
||||||
const value = localStorage.getItem(keyName) |
|
||||||
|
|
||||||
if (value) { |
|
||||||
return JSON.parse(value) |
|
||||||
} |
|
||||||
localStorage.setItem(keyName, JSON.stringify(defaultValue)) |
|
||||||
return defaultValue |
|
||||||
} catch (err) { |
|
||||||
return defaultValue |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
const setValue = (newValue: any) => { |
|
||||||
try { |
|
||||||
localStorage.setItem(keyName, JSON.stringify(newValue)) |
|
||||||
} catch (err) { |
|
||||||
/* eslint-disable-next-line */ |
|
||||||
console.log(err) |
|
||||||
} |
|
||||||
setStoredValue(newValue) |
|
||||||
} |
|
||||||
|
|
||||||
return [storedValue, setValue] |
|
||||||
} |
|
||||||
Loading…
Reference in new issue