react-use
react-use copied to clipboard
useLocalStorage without 'or undefined'
[isEasyToUse, setIsEasyToUse] = useLocalStorage("easyToUse", false)
Why value is boolean | undefined?
i think you will provide more infomation
I'm surprised by this too, I expected the following to return the same types for the state and the state dispatcher
const [localStorageArray, setLocalStorageArray] = useLocalStorage<string[]>('some-array', [])
const [stateArray, setStateArray] = useState<string[]>([])
localStorageArray
isstring[] | undefined
setLocalStorageArray
is Dispatch<SetStateAction<string[] | undefined>>
stateArray
is string[]
setStateArray
is Dispatch<SetStateAction<string[]>>
I would expect this if the initialValue
isn't set, but we are passing in an []