-
Notifications
You must be signed in to change notification settings - Fork 97
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
Initial state #25
Comments
I'm very interested in this behavior. Do you want this as PR @donavon or is it more of a fork addition? |
+1 I have |
I have made a module that solves this problem by making a special function called |
I definitely like the idea and mostly of how it's implemented, but the somewhat big caveat to me as DRY guy is repeating the initial state. I mean with regular
useState
it does make sense as it's isolated but looking at this like a "shared" state, there should definitely be a single place to declare initialState.I would propose to expand API like
createPersistentState(key, initialState)
. I know there is another argument forstorage
, but that's likely to be used rarely, so it can be at 3rd place just fine :) Alternatively, it could make sense to export another function with currying behavior where storage would be specified in the first argument and it would return factory bound to that storage type.Of course, it would still be possible to specify an initial state directly in a component, but it would be optional. Perhaps it could even show DEV-only warning to keep such state unified.
The text was updated successfully, but these errors were encountered: