Skip to main content

avoid-misused-hooks

added in: 1.17.0
Pro+

Warns when hooks are used in non-hook widgets.

Example

❌ Bad:

class SomeWidget extends StatelessWidget {
const SomeWidget();


Widget build(BuildContext context) {
useMemoized(() => {}, keys); // LINT: Avoid using hooks in non-hook widgets.

return Container();
}
}

✅ Good:

class SomeHookWidget extends HookWidget {
const SomeHookWidget();


Widget build(BuildContext context) {
useMemoized(() => {}, keys); // Correct, the widget is a 'HookWidget'

return Container();
}
}