Explain the specific mechanism by which `React.memo` prevents unnecessary re-renders, focusing on how it differs from a simple equality check on props.
`React.memo` is a higher-order component (HOC) that optimizes functional component performance by preventing re-renders when the component's props have not changed. The key mechanism it employs is a *shallow comparisonof the component's props. This shallow comparison is the crucial difference from a simple equality check. A simple equality check (using `===` in JavaScript) only compares if two variables point to the *sameobject in memory. If a prop is an object or an array, even if its contents are identical to the previous render, a simple equality check will return `false` because it's a different object in memory. `React.memo` performs a shallow comparison, meaning it checks if the references to the prop objects have changed. For primitive types (numbers, strings, booleans), it compares their values directly using `===`. However, for objects and arrays, it only checks if the *referenceto the object/array is the same. If the parent component re-renders and creates a new object or array with the same values as before, even though the *contentsare identical, `React.memo` will detect a change (because the object reference is different) and re-render the component. To customize this behavior, `React.memo` can accept a second argument: a custom comparison function. This function receives the previous and next props as arguments and should return `true` if the component *shouldupdate (even if the references are the same) and `false` if the component should *skipthe update. This allows for more complex logic to determine if a re-render is necessary, such as comparing the *contentsof objects or arrays, rather than just their references. Without the custom comparison function, `React.memo` relies solely on the shallow comparison of prop references, which is more efficient than deeply comparing object contents but can still trigger unnecessary re-renders if new objects are created on each parent render even with the same data.