Flutter hooks are matched by call order, so deleting one resets every hook after it
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.
At a glance
- What is it?
- flutter_hooks replaces a StatefulWidget's State object with a List of Hook held on the Element and fetched by index, which removes the duplication of initState and dispose and creates three ordering rules in return. The cost is visible in the hot reload section, where removing a hook hard resets the state of every hook below it.
- Who is it for?
- flutter_hooks earns its place when you have several widgets that each need the same lifecycle logic, since the library's whole argument is that initState and dispose code should be written once and called rather than copied. Before you adopt it for a large widget, know what you are taking on.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 6 days ago.
- What is it written in?
- Mainly Dart, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- rrousselGit/flutter_hooks3,331 ★ · +0
| Repository | 2026-09-24 | 2026-11-15 |
|---|---|---|
| rrousselGit/flutter_hooks | 3.3k | 3.3k |
0 Stars in the last 52 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Hooks are identified by index, not by function
The principle section explains the mechanism in about a paragraph. Like State, hooks are stored in the Element of a Widget, but instead of one State the Element holds a List of Hook, and using a hook means calling Hook.use. What use returns depends on how many times it has been called: the first call returns the first hook, the second returns the second, and so on. A naive implementation is given to make the consequence obvious:
class HookElement extends Element {
List<HookState> _hooks;
int _hookIndex;
T use<T>(Hook<T> hook) => _hooks[_hookIndex++].build(this);
@override
performRebuild() {
_hookIndex = 0;
super.performRebuild();
}
}There is no lookup by name and no comparison of the passed hook against the stored one. A counter walks the list on every rebuild and is reset to zero before the rebuild runs, so position in the call sequence is the identity.
Deleting a hook hard resets the hooks after it
Because position is identity, refactoring is where the design bites, and the hot reload section walks through it. Start with three calls: useA, useB(0) and useC. Editing an argument after a hot reload is safe. Changing useB(0) to useB(42) keeps every hook's state, because the positions are unchanged. Removing a hook is not safe. Delete useB and the sequence becomes useA and useC, and the result is that useA keeps its state while useC is hard reset. The stated reason is that when a hot reload follows a refactor, all hooks after the first impacted line are disposed of. In a widget with ten hooks, deleting the third therefore resets the remaining seven, and any state they hold is gone rather than restored.
Mixins were the option the library argues against
The motivation section starts from a specific complaint about StatefulWidget, namely that it is very difficult to reuse the logic of initState or dispose, with AnimationController as the worked example: every widget that wants one reimplements almost all of that code. Dart mixins are offered as a partial fix, and then two problems with them are listed. A given mixin can only be used once per class, which rules out combining several behaviours in one widget. And a mixin and the class share the same object, so if two mixins define a variable under the same name the result may vary between a compilation failure and unknown behaviour. That second one is the sharper objection, because it turns a naming collision into something the compiler may or may not catch. Hooks are proposed as a third solution to the same duplication problem.
Hooks only work inside build of a Hooks widget
The first of the specificities is a hard constraint: hooks can only be used in the build method of a widget that mixes in Hooks. Three rules follow from the index mechanism, and each one maps to a way the mapping can break. Always prefix your hooks with use, so a reader can tell what is a hook, on the grounds that a function called myHook would confuse people into thinking it is not one. Call hooks unconditionally. And never wrap a use call inside a condition. That last rule is the direct consequence of the counter: a hook skipped on one rebuild but present on the next shifts every later hook by one position, and the state that was stored at a position is handed to a different hook.
The same hook can be used many times in one widget
The second specificity is what fixes the mixin limitation. The same hook can be reused arbitrarily many times, and calling useAnimationController twice produces two independent controllers that are both preserved when the widget rebuilds. Where a mixin could only be applied once per class, a hook is a value produced by a call, so repetition costs nothing. The third specificity explains why hooks can be published: hooks are entirely independent of each other and from the widget, which means one can be extracted into its own package on pub and used by someone who has never heard of your widget. That independence is also what makes composability work, since a custom hook can call other hooks without knowing anything about the widget that will call it.
The AnimationController diff is the entire pitch
The before and after examples are short enough to compare line by line. The StatefulWidget version is a widget class with a final Duration, a createState returning a private State class mixed with SingleTickerProviderStateMixin, a late final AnimationController, an initState that constructs it with vsync and duration, and a didUpdateWidget that compares the incoming duration against the old widget's. It continues past the visible part of the example. The replacement is a widget extending HookWidget with the same constructor, and a build method of four meaningful lines: a call to useAnimationController with the duration, then a Container. The documentation states the two are functionally equivalent, that the controller is still disposed and its duration still updates when the widget's duration changes, and then asks where the logic went.
Five translations live inside the package directory
The repository root holds four entries: .github, LICENSE, README.md and a packages directory, and the package itself is under packages/flutter_hooks, which is where the translated READMEs are kept, one per language under resources/translations, covering Portuguese, Korean, Simplified Chinese and Japanese alongside the English original. So the documentation a user reads is versioned with the code rather than kept on a docs site, and every language copy has to be updated by hand when the English one changes. Distribution runs through pub.dev, with a badge linking to the package page, and there are no GitHub releases, so the published package version rather than a tag is the thing to pin. The README also links a codecov report and an awesome-flutter list, and the hook list itself is anchored inside the same file rather than living on a separate site.
Creating custom hooks as functions or classes
The documentation describes two ways to create a hook. A function can compose existing hooks and is conventionally prefixed with `use`; the example combines `useState` and `useValueChanged` to log changes. For more complex behavior, implement a `Hook` and `HookState`, which expose lifecycle methods such as `initHook` and `dispose`. A small `use` function can wrap that class to provide the public API.
Editorial conclusion
flutter_hooks earns its place when you have several widgets that each need the same lifecycle logic, since the library's whole argument is that initState and dispose code should be written once and called rather than copied. Before you adopt it for a large widget, know what you are taking on. Hooks are identified by the order they are called in, not by which function they are, so the three rules about naming, unconditional calls and conditions are not style advice. Refactoring that inserts, removes or reorders hooks will reset the state of hooks after the change, which during hot reload looks like the widget losing data. The library ships on pub.dev rather than through releases, the repository root is almost empty with everything under packages/, and the README is the primary documentation, including the five translations kept inside the package directory.
Frequently asked questions
What is flutter_hooks in Dart?
It is a Flutter implementation of React hooks, published on pub.dev under the MIT licence. Where a StatefulWidget's Element holds one State object, a HookWidget's Element holds a List of Hook, and a hook is obtained by calling Hook.use, which returns the hook matching the number of times use has been called so far in that build.
How do flutter_hooks differ from StatefulWidget?
StatefulWidget makes the logic of initState and dispose hard to reuse, so every widget wanting an AnimationController reimplements it. A HookWidget moves that logic into a function such as useAnimationController called from build, which the documentation says is functionally equivalent: the controller is still disposed and its duration still updates when the widget's duration changes.
What are the rules for calling a hook in flutter_hooks?
Prefix the name with use, call hooks unconditionally, and never wrap a use call in a condition. Hooks can only be used in the build method of a widget that mixes in Hooks, and they are identified by the order they are called in rather than by which function they are.
Does hot reload reset hook state in flutter_hooks?
Editing an argument is safe: changing useB(0) to useB(42) keeps every hook's state. Removing a hook is not. After a hot reload following a refactor, all hooks after the first impacted line are disposed of, so in a sequence of useA, useB and useC, deleting useB hard resets useC while useA keeps its state.
How do you write your own hook in flutter_hooks?
The documentation describes two approaches: compose existing hooks in a function conventionally named with a use prefix, or implement a Hook and HookState for more complex lifecycle behavior. A function can wrap the class-based hook to provide a convenient API.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/rrousselgit-flutter-hooks)Star history chart for your README
[](https://hysenlabs.com/projects/rrousselgit-flutter-hooks)Was this useful?