Hello Guys, Let’s learn hooks in React.
What are Hooks?
Hooks are new features in React which help you to write a code using function components only means no more class components required. Functional components in react make coding easier than class components.
So Hooks will not work inside the class components so don’t try to use it with class components. Hooks are designed to overcome the limitation of function components compare to class components.
Those who have worked with Class Components they already know this keyword increase coding confusion.
We always need to bind the event handler inside the constructor with Class Components
Classes make our code lengthy and make hot reloading unreliable
Class Components make code harder to follow
It becomes complex to organize related code in one place. For example Event Listener we will register with componentDidMount and will unregister with componentWillUnmount
There are many other reasons which forced the developer to think about new concepts like Hooks which can help to complete code with functional Components.
Hooks doesn’t mean classes are removed, classes are also there in React. But Hooks provide a more direct API to the React concepts you already know.
So I think that’s enough discussion about React Hooks. Let’s see different Hooks with Example.