usehooks
usehooks copied to clipboard
Adds tuple type in order to be able to access storedValue and setValue correctly
In the useLocalStorage
hook Typescript example, an explicit type is required for the function in order to be able to use the tuple correctly: [T, (value: T | ((val: T) => T)) => void]
.
Without this, the type for both storedValue
and setValue
is string | ((value: string | ((val: string) => string)) => void)
which prevents using them properly.
If it looks a little ugly inline I can change it for a declared type
. :+1: