A helper function that lets us write stateful React components in the same functional style as stateless components.
- sidesteps the need to introduce
this-binding confusion into your codebase.
- slightly terser, slightly more declarative
- opinionated - doesn't expose the more dangerous features of class-based Components (e.g. lifecycle callbacks)
When you have a team working on a larger React codebase it is hard for everyone to understand which patterns are preferable vs. those which are a necessary compromise.
In my opinion stateful components are sometimes neccessary in a React app but there aren't many other good reasons to implement a component using the class-based approach. This helper allows us to implement stateful components without having to introduce a class-based component. This helps to make a class-based component an odd case which hopefully stands out for further discussion.
Additionally, this helper removes the need for boilerplate
this-binding of handler functions. It's distracting, hard for folks to learn, and very easy to miss.