src/data/question-groups/react/content/re-renders.md
Unnecessary re-renders in components can occur due to several reasons, and it's important to optimize your code to minimize them for better performance.
Here are some common reasons for unnecessary re-renders in functional components:
useCallback hook to memoize the function.useState hook with objects: If you use useState hook with objects, you need to make sure that you are not mutating the object. If you mutate the object, React will not be able to detect the change and will not re-render the component. You can optimize this by using useReducer hook instead of useState hook.useEffect hook without dependencies: If you use useEffect hook without dependencies, it will run on every render. You can optimize this by passing an empty array as the second argument to useEffect hook.React.memo to memoize the child component where possible.useSelector hook to select only the state that you need in a component.useContext hook to select only the data that you need in a component.You can also use React.StrictMode to detect potential problems in your code that could cause unnecessary re-renders.