-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Expose keys in useState
#441
Comments
That's just how it is in React |
Meaning you would not want to touch it? I feel like an optional parameter is a nice escape hatch, while keeping the default behaviour consistent with react |
Seems like #347 was also looking for this. At least a It could also help alleviate some of the confusion, since the |
I'd rather not have the core React hooks deviate too much from React. |
I see the reasoning for requesting this feature, and I have also wished React had the same. btw, @rrousselGit , unrelated, but I love this library. I can't think of any better state manager. I wonder why hooks are not a core part of Flutter itself. Thanks for doing this ❤️ |
Is your feature request related to a problem? Please describe.
Multiple times now I've been surprised by the fact that
useState
doesn't allow for setting custom keys that trigger a reevaluation of the state. A simple use-case is rebuilding a widget whenever aPageController
page changes.This code works in principle, until
pageController
changes. This change will not get picked up byuseState
.Describe the solution you'd like
Add optional keys to the
useState
hook.Describe alternatives you've considered
For the given example, one might suggest
useListenable
, but that will rebuild way too often.Another option would be:
However, this is verbose, imperative, and not really readable (it might also add an extra rebuild?).
Additional Context:
Riverpods
StateProvider
is a nice example for a bridge between declarative re-evaluation usingref
and imperative modification using.state
The text was updated successfully, but these errors were encountered: