I've read a lot about hooks, the reasoning all makes sense but I'm still not fully getting it at an intuitive level. Like I get that it means you can write functional versions of class based components, an example of a complex class component that has been converted to a function with hooks would be good. The counter example really leaves a lot to the imagination. The examples in https://usehooks.com/ aren't convinci…
A major point of Hooks is that they’re composable — unlike lifecycle methods. You can separate different reusable pieces of logic into Hooks, and then combine them or pass values between them. You can even call the same Hook more than once. I’ve wrote about new possibilities they unlock here: https://medium.com/@dan_abramov/making-sense-of-react-hooks-... Hope this helps.
class Foo extends React.Component {
constructor(props) {
super(props)
this.useEffect(…);
this.useState(…);
// or maybe even a top-level API:
useState(this, …);
}
}