? Power of 11 React Hooks
? Power of 11 React Hooks
useState
This React hook allows components to manage local
state without class components.
Example:
Swipe Left 02
2. useEffect
useEffect is used for tasks like data fetching, setting up
subscriptions, and performing initial actions. It
behaves similarly to componentDidMount in class
components
Example:
Swipe Left 03
3. useContext
useContext allows you to access the value of a
context directly in a functional component, without
needing to use a higher-order component like
Consumer
Example:
Swipe Left 04
4. useRef
It is used to create mutable references to DOM
elements and any values that you want to persist
across renders without causing re-renders.
Swipe Left 05
5. useMemo
Returns a cached value and prevents expensive
calculations from running on every render.
Example:
Swipe Left 06
6. useCallback
Memoizes a function, ensuring that the function
reference remains stable across re-renders unless its
dependencies change. This is especially useful when
passing functions down to child components, as it
prevents unnecessary re-renders.
Example:
Swipe Left 07
7. useReducer
Useful when state management is more complex
than a simple state change (like useState)
Like useState, useReducer is local to the
component, but it gives you more flexibility and
control over how the state is updated.
Example:
Swipe Left 08
8. useLayoutEffect
Like useEffect, but fires synchronously after the
DOM has been updated but before the browser
has painted the changes
Example:
Swipe Left 09
New & Cool React Hooks!
9. useId
useId is a Hook that generates unique, stable IDs that
are consistent across re-renders
Example:
Swipe Left 10
10. useDeferredValue
Defers updates to prevent UI lag during heavy
computations.
Example:
Swipe Left 11
11. useTransition
Allows non-blocking UI updates for better user
experience. It’s pertcularly useful when you need to
update multiple states without rendering immidietly
Example:
Swipe Left 12