This discussion in github
https://github.com/flutter/flutter/issues/19269
discusses the reasons you should use a Stateless class definition over a function component to define your Widget compositions.
Widget functionWidgetComposition() => Text('hello');
class MyWidgetComposition extends StatelessWidget {
Widget build(BuildContext context) => Text('hello');
}
If I understood correctly, the reasons to use Stateless are the following...
- Do I need access to context?
- Do I care that it won't be rebuilt via hot reload? (or will I remember)
- Do I need to associate my Widget with a key?
- Will this Widget ever be a constant?
- Does this widget ever need to be rebuilt?
It feels quite compelling to always use Stateless as a fairly standard rule but the functional style is so much more concise, especially when you have a few parameters. I feel functional components will improve readability in my code. Should I always use Stateless classes then or is it ok to use what React call functional components in some situations?