Skip to content
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

Merged
merged 5 commits into from
Apr 21, 2024

Conversation

michaela9
Copy link
Contributor

Problem

items are not persisted in memory

Describe your changes

create persisted items with custom useLocalStorage hook

closes #7

src/app/hooks/useItemsStore.ts Show resolved Hide resolved
src/app/hooks/useLocalStorage.ts Outdated Show resolved Hide resolved
return storedValue
? JSON.parse(storedValue)
: JSON.parse(
localStorage.getItem('items') ??
Copy link
Contributor

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

src/app/hooks/useLocalStorage.ts Outdated Show resolved Hide resolved
src/app/hooks/useLocalStorage.ts Outdated Show resolved Hide resolved
@michaela9
Copy link
Contributor Author

Thanks for code review. Now it definitely looks better. Last thing are failing tests :(

@tomastauer
Copy link
Contributor

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

@tomastauer tomastauer merged commit 466074a into oss-institute:master Apr 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🪶 Keep the todo list history
2 participants