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

small hydration improvements #47

Merged
merged 3 commits into from
Oct 16, 2023
Merged

Conversation

fa-sharp
Copy link
Contributor

This implements the small changes discussed in #46.

If the onInit parameter passed to the hook is a function, it is run to reset the render value when the storage unmounts. This allows the advanced use case of handling the loading/hydration state in the onInit function.

I also renamed the boolean parameter to isHydrated, which better describes the state it represents. This is purely a documentation change.

@louisgv louisgv self-requested a review October 16, 2023 00:37
src/hook.ts Outdated
@@ -92,6 +92,7 @@ export const useStorage = <T = any>(rawKey: RawKey, onInit?: Setter<T>) => {
return () => {
isMounted.current = false
storageRef.current.unwatch(watchConfig)
if (onInit instanceof Function) setRenderValue(onInit)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's put this under block inside curly brackets to keep it consistent with the repo

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.

Beside the nits, LGTM! Once it's fixed, I will merge and cut a new release likely next week?

@fa-sharp
Copy link
Contributor Author

Fixed formatting! Let me know if there's anything else. Thanks!!

@louisgv louisgv merged commit da98f04 into PlasmoHQ:main Oct 16, 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.

2 participants