-
Notifications
You must be signed in to change notification settings - Fork 95
Description
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 for storage, 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.