Introduction of React Hooks

Nahidul Islam
2 min readNov 7, 2020

Today I am discussing the most popular JavaScript library React Hooks. I think it can help all of you.

Photo by Ferenc Almasi on Unsplash

In React, the new addition of 16.8 Hooks are available. The most important is that Hooks is not used in class components, it is used in functional components. There are multiple reason hooks are need in react application. Some of the reason is “ use of ‘this’ keywords”, reusable stateful logics, simplifying complex scenarios.

UseSate Hook:

Functional components are more commonly used in ReactJS components. Most of the developers prefer to use functional components over class-based components. The main reason is functional components require is very less coding, that’s why most of the developers prefer functional components. One of the two main features of the class is lost when using functional components. Another main feature is the use of lifecycle, its control of how components look behave at the separate stages. The two most used hooks are the useState() hook, which allows functional components to dedicate their state, and the useEffect() hook, which allows functional components to manipulated DOM elements before rendering. usState() hook allow one to declare a state variable inside function.Most important is that one useState() can only use for one state variable.

useEffect():

useEffect() hook, which allows functional components to manipulated DOM elements before rendering and it updating the DOM elements, fetching data from API. When we specify that useEffect we request react to execute the function that we pass in the useEffect function arguments, every time components are rendering. The most things are that useEffect is used inside the functional components buy doing this we can easily access the components state and props without having to write any additional code.

That’s all today, next time I will share another important topic.

--

--

Nahidul Islam

AWS Certified Solutions Architect - Associate || DevOps Enthusiast || JavaScript Developer at SEBPO