Why can inline objects and functions as props hurt memoisation?

React performance · Freshers and experienced

Model answer

A new object or function is created on each render, so its reference differs every time, and React.memo sees "changed" props and re-renders the child. Fix by moving constants outside the component, or memoising with useMemo and useCallback when the child is memoised.

If the child is not memoised, this does not matter.

Learn this topic

React Performance: memo, useMemo, useCallback and When Not to Use Them in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions