How can you prevent a functional component from re-rendering when its parent re-renders, even if its props haven't changed?
- Use the React.memo higher-order component.
- Use shouldComponentUpdate in a class component.
- Use PureComponent in a class component.
- Use useMemo hook with functional components.
To prevent a functional component from re-rendering when its parent re-renders, even if its props haven't changed, you can use the React.memo higher-order component (HOC). This HOC memoizes the component, and it will only re-render if its props have changed. Options 2 and 3 are methods applicable to class components, and option 4 is a hook for memoizing values, not components.
Loading...
Related Quiz
- In Redux, where is the application's state held centrally?
- If you need to render a child into a different DOM node, outside of the parent DOM hierarchy, you would use a React Portal.
- When using Render Props, which React concept allows the parent to access the state of the child component?
- To avoid flooding a React application with too many real-time updates, a technique that involves grouping multiple updates and delivering them in batches is called ________.
- In React, what are synthetic events?