Sobes.tech
Middle+

Milliseid argumente võtab React.memo vastu peale enda komponendi?

sobes.tech AI

Vastus AI-lt

React.memo accepts two arguments:

  1. Component, which you want to memoize — usually a functional component.
  2. Comparison function (optional) — takes two props objects (prevProps and nextProps) and returns true if the props are considered equal and a re-render is not needed, or false if 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.