avoid-unnecessary-hook-widgets
Warns when a hook widget or HookBuilder
does not use hooks.
A hook widget that does not use hooks can be converted to a regular widget which will simplify your code.
Example
❌ Bad:
// LINT: This widget does not use hooks and can be converted to a regular widget.
class MyWidget extends HookWidget {
const MyWidget();
Widget build(BuildContext context) {
return Container();
}
}
// LINT: This widget does not use hooks and can be converted to a regular widget.
final hookBuilder = HookBuilder(
builder: (context) {
return Container();
},
);
✅ Good:
class MyWidget extends HookWidget {
const MyWidget();
Widget build(BuildContext context) {
useMemoized(() {});
return Container();
}
}
final hookBuilder = HookBuilder(
builder: (context) {
useMemoized(() {});
return Container();
},
);