Member-only story
React hooks are something that everyone uses at the moment. A nice feature that no one seems to understand what they are. Each time I ask someone what are hooks, usually response is they are useState and useEffect functions. Those are examples of hooks, but it doesn’t answer what they are. And in this post, I am trying to simplify what they are.
Background
When I started working with React, I loved writing class components. Even when functional components started becoming popular, I still kept writing classes. But they do suffer from some critical issues. Class components are harder to minimize. There is much boilerplate code, and don’t get me even start on the issue with this keyword. Functional components are much cleaner, but there was a problem of access to the state and lifestyle components. It is where React hooks come. They enable access to React features from function components. And the following are two examples of hooks you get with React and how they make your life easier.
State hook
For accessing to component state, there is the useState hook. With the class components, you would need to use a whole set of lifecycle methods. First, you would need a constructor to set up the initial state, then making functions to update the state. Each time you create those functions, there is an issue with this. I still…