Welcome all for another topic in React is Hooks.
What are Hooks?
React Hooks are like JavaScript functions that we can use to isolate the reusable part from a functional component.
Hooks can be stateful and can manage side-effects.
Hooks are like different coffee cups that are used for different purposes. Just like different hooks use for differnt purpose in React.
The Different types of Hooks are:
- UseState()
- UseEffect()
- UseReducer()
- UseContext()
- UseRef()
Now, we will see how these hooks works in different cases.
- UseState(): It allows to add state to functional components.
2.UseEffect(): It allows to perform side effects in your components. Side Effects like: fetching data,directly updating the DOM, and timers.
3.UseReducer():It is similar to useState Hook.It is mainly used to handle complex state updates. It means if there are two state updates of similar type with slight change, we can combine them to single state known as useReducer().
4.UseContext: The main reason for using this UseContext is to centralize the state. It avoids props drilling.
5.UseRef: It allows you to access the elements and its inner values mainly for inputs and manipulate them.
Hope you guys enjoy learning about Hooks.
Meet u with more topicsðŸ¤
Top comments (0)