-
-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Just spent some time debugging and issue where I'm writing a test like:
function TheComponent() {
const [value, setValue] = useLocalStorageState("storage-key");
return <div>{value}</div>
}
//test
localStorage.set("storage-key", "2024-05-01T12:00:00Z");
render(<TheComponent/>)
And wondering why it didn't seem to be respecting the existing localStorage values.
Turns out because I hadn't provided a serializer property in the options object, the default parseJSON serialization is throws, and then the default value is used.
It would be to be aware that this is happening and either:
- (easy) - console.warn to tell the developer that serialization has failed
- (breaking change) - Throw an error if serialization fails. Provide an 'opt out of errors' option if the user wants to supress this option.
- (non-breaking middleground) - provide an opt in - 'throw if serialization fails' option.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request