-
Notifications
You must be signed in to change notification settings - Fork 5
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
create persisted items with custom useLocalStorage hook #16
create persisted items with custom useLocalStorage hook #16
Conversation
src/app/hooks/useLocalStorage.ts
Outdated
return storedValue | ||
? JSON.parse(storedValue) | ||
: JSON.parse( | ||
localStorage.getItem('items') ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to load the "default key", in this case "items". The key
argument passed to the hook cannot be undefined, so there is no need for default value
Thanks for code review. Now it definitely looks better. Last thing are failing tests :( |
the reason for failing tests is keeping the state between the test cases (as the local storage is available to some extent for tests as well, storing something in one test will influence the others) I have added clean up to the test file, now the tests will pass |
Problem
items are not persisted in memory
Describe your changes
create persisted items with custom useLocalStorage hook
closes #7