Reputation: 38143
The documentation for useMemo
says:
You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without useMemo — and then add it to optimize performance
React.memo
and shouldComponentUpdate
have similar warnings.
I have a case, however, where I want a functional component not to update under certain conditions. I am looking for memo-like functionality not for performance, but for the semantic guarantee of there being no update given some conditions. How do I address this issue?
Upvotes: 10
Views: 1374