Middle+
Milliseid argumente võtab React.memo vastu peale enda komponendi?
sobes.tech AI
Vastus AI-lt
React.memo accepts two arguments:
- Component, which you want to memoize — usually a functional component.
- Comparison function (optional) — takes two props objects (prevProps and nextProps) and returns
trueif the props are considered equal and a re-render is not needed, orfalseif the component should be updated.
Example with a comparison function:
const MyComponent = React.memo(function MyComponent(props) {
// rendering
}, (prevProps, nextProps) => {
// compare only the necessary fields
return prevProps.value === nextProps.value;
});
If the comparison function is not provided, React.memo performs a shallow comparison of props by default.