-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useLocalStorage without 'or undefined' #2551
Comments
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[]>([])
I would expect this if the |
Fixes streamich#2551 Instead of using a single function which accepts `defaultValue?: T` - which forces a return type of `T | undefined`, use an overload. When a defaultValue is supplied, the useState-like tuple returned uses `T`. When no defaultValue is supplied, it's `T | undefined`. Runtime usage is exaclty the same, this just improves the types.
[isEasyToUse, setIsEasyToUse] = useLocalStorage("easyToUse", false)
Why value is boolean | undefined?
The text was updated successfully, but these errors were encountered: