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

feat: make the storage key reactive #42

Merged
merged 6 commits into from
Sep 8, 2023

Conversation

fa-sharp
Copy link
Contributor

Fixes #36 by making the useStorage key parameter reactive.

I added a useRef to track the current renderValue within the hook. This avoids us from adding dependencies to some of the callbacks and so it prevents needless un-mounting and re-mounting of the storage.

I added a test to ensure the storage unmounts and re-mounts properly when the key changes.

Note: this only makes the string key reactive, not a custom Storage paramater that's passed in. If someone wants to switch between different Storages (sync and local, for example) using the same hook, it won't happen automatically since the Storage parameter is not reactive (this might be another PR if I can figure out how to make it happen)

@louisgv louisgv self-requested a review August 19, 2023 18:53
@louisgv
Copy link
Contributor

louisgv commented Aug 19, 2023

Thanks for the PR! :D

Copy link
Contributor

@louisgv louisgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Let's just merge this in and see how it works - Sorry I've been away for a bit! Completely forgot about this PR 🙏

@louisgv louisgv merged commit 018ca17 into PlasmoHQ:main Sep 8, 2023
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.

Make the key reactive in useStorage hook
2 participants