rrousselGit / flutter_hooks

React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
MIT License
3.14k stars 179 forks source link

implement useGlobalState #57

Closed iambudi closed 5 years ago

iambudi commented 5 years ago

What is best practice to use global state without having intermediary sharedPreference?

rrousselGit commented 5 years ago

Hooks are not a state management library, at least not by default.

They allow some pretty powerful stuff in that matter, but flutter_hooks will hardly suggest one over another. You're free to use redux, bloc, mobx or whatever you like in combination with hooks. Or even bake your own

iambudi commented 5 years ago

I thought when i read the example code final counter = useState<int>(5); that can increment the value and update the UI it holds the local state. Thanks for the clarification.

rrousselGit commented 5 years ago

That is the case. But this is equal to creating a counter property on a State subclass. It's not a global state

You can make one though. In react, there are multiple user made hooks that do something similar. But it's completely outside of the scope of this library.

ianldgs commented 3 years ago

@rrousselGit any ideas on how to create such hook? I'd imagine something related to context, but unlike react, we can't create a new context and use a provider to assign a custom value and dispatch in a tree. Also inherited widget doesn't sound practical.

rrousselGit commented 3 years ago

See Riverpod, it's similar