-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Examples for complex cases with useState hook #347
Comments
What does that mean exactly? I do not understand this bit. |
I'll try to explain, using React references. Again, I'm very new to Flutter and Dart, sorry about that. In react, when I pass an object like so
the child re-renders when that object is replaced in the parent. For example:
will trigger a re-render of
I tried to do the same in Flutter. But it's not working. I receive an updated prop inside widget, but it does not trigger a state initialiser for the hook. I hope now the problem is more clear. |
You mean that if |
The state never resets for me on React. Maybe you're confused and your state was reset for reset reasons? Like tree shape change or key change, which causes the component to be unmounted. |
No, I mean if you have |
That's what I meant. I tried and didn't see this behavior. Do you maybe have a react example? |
Okay, I feel like I made a mistake there. I'll update once I've done investigating. |
Indeed you were right. I was confused about React behaviour. However, what do you think about adding more examples? I understand that mostly we can look at react examples, but it wouldn't hurt to have specific Flutter examples, right? |
I don't have time to work on examples. Feel free to contribute some if you want to. |
Describe what scenario you think is uncovered by the existing examples/articles
Hello! I'm new to Dart and Flutter, but I've used React a lot. Since this library is a port of React hooks, I'd suggest to provide more examples of how hooks could be used. Especially the cases, where it's different from react.
I'd suggest to have an example section, which could be filled with the help of the community.
Describe why existing examples/articles do not cover this case
I struggle to understand even such a simple hook as
useState
in Flutter.It seems that Dart (or Flutter, or this library) behave different from React hooks when complex objects are passed.
For example, I specifically struggle with this situation:
I have a Sealed Union built by freezed as a representation of the state.
When the
exercise
prop is passed, I expect the state to initialise.This works for the render of the widget. However, after the
exercise
prop changes in the parent widget, the state keeps the previous value.I'm not sure what is the issue. Maybe I misunderstand how Flutter works, but I'd definitely expect the desired behaviour in React.
Code for reference:
It would be wonderful to have complex cases as examples somewhere in the docs.
I'd gladly contribute myself, if you agree with the notion proposed.
The text was updated successfully, but these errors were encountered: