What are Pure Components?
What are Pure Components?
Pure Components in React are a way to optimize the performance of class components by preventing unnecessary re-renders. A React component is considered pure if it renders the same output for the same state and props. This means that if the component's state or props have not changed, the component will not re-render, thus saving on performance costs associated with rendering.
React provides the React.PureComponent base class for creating pure class components. When a class component extends React.PureComponent, it is treated as a pure component. This is because React.PureComponent automatically handles the shouldComponentUpdate() lifecycle method by performing a shallow comparison of the current props and state with the new ones. If there are no changes detected in the state or props, the shouldComponentUpdate() method returns false, preventing the component from re-rendering.
Here are some key points to remember about React Pure Components:
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.