memo
React.memo
lets you skip re-rendering a component when its props are unchanged.
Wrap a component in memo to get a memoized version of that component. This memoized version of your component will usually not be re-rendered when its parent component is re-rendered as long as its props have not changed.
But React may still re-render it: memoization is a performance optimization, not a guarantee.arePropsEqual
In React, memo can accept an optional argument called "arePropsEqual". This function takes two arguments: the previous props and the new props of the component. It should return true if the old and new props are the same, meaning the component will produce the same output and behavior with the new props as it did with the old ones.
In ReScript, you can use the arePropsEqual
function with the React.memoCustomCompareProps
binding. However, React.memoCustomCompareProps
cannot be combined with @react.component
.
To work around this, you can redefine the make binding:
Another approach is to use a custom prop type and remove the @react.component
annotation.