DEV Community

Harshit Verma
Harshit Verma

Posted on

Hooks in React

Hooks play a very important role in the React application. It helps us to add functionalities in the application.Β 

We can use hooks only in functional components.

Hooks :-

  1. useState()
  2. useEffect()
  3. useReducer()
  4. useRef()
  5. useMemo()
  6. useCallback()
  7. useLayoutEffect()
  8. useId()
  9. useContext()

state Management: useState for the simple state management while useReducer for the complex state management.

Side effects: useEffect can be used for the side effects like data fetching.

Dom manipulation: useRef helps to access the DOM elements.

Sharing global data: useContext helps us to share the state between the components and avoids the prop drilling.Β 

Performance optimization: useMemo and useCallback both hooks help to optimize the performance of the application by memorizing the value and function.
useMemo avoids the unnecceary calculations.
useCallback avoids the unnecessary re-rending components.

generate unique ID: useId can be used to generate unique IDs.

for more details : Learn React Hook

Top comments (0)