1. useState
useState
is a hook that allows functional components to manage local state. It returns a stateful value and a function to update it, enabling you to create dynamic and interactive UIs.
2. useEffect
useEffect
is used for side effects in functional components. It lets you perform tasks like data fetching, subscriptions, or manually changing the DOM in a clean and efficient way.
3. useRef
useRef
returns a mutable object called a ref
object, which has a .current
property. It is commonly used to access and interact with the DOM directly or to persist values across renders without causing re-renders.
4. useReducer
useReducer
is a powerful alternative to useState
for managing more complex state logic. It accepts a reducer function and an initial state, providing a dispatch function to update the state based on actions.
useLayoutEffect
is similar to useEffect
but fires synchronously after all DOM mutations. It's useful when you need to perform measurements or manipulate the DOM immediately after the browser paints.
useImperativeHandle
customizes the instance value that is exposed when using React.forwardRef
. It allows you to control which properties of the component are exposed to the parent component when using ref
.
7. useContext
useContext
is used to consume values from a React context. It allows functional components to subscribe to a context's changes, providing a more straightforward way to share values like themes or authentication states.
8. useMemo
useMemo
memoizes the result of a function, preventing unnecessary recalculations. It is beneficial for optimizing performance by caching expensive calculations or references.
9. useCallback
useCallback
memoizes a callback function, preventing it from being recreated on each render. It is useful when passing callbacks to child components to avoid unnecessary re-renders.