Category: Next.js, React and TypeScript

React useMemo returns old results after filter change

Read this guide in Polish

Changing the selected category does not update the list until another field is changed. The result of the memoir depends on the value omitted in the dependenties array, so React reuses the outdated calculation.

How to identify the source of the problem

Check all values read in callback useMemo, including parameters and auxiliary functions. Compare the content of the dependencies array with the values that actually affect the filter result.

Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.

Repair steps

Add all dependencies to useMemo or remove memoization if filtering is cheap and does not require optimization. In the case of data altered by mutation repair, also state updates so that dependency receives new references.

How to Test Solution

After changing each filter, the list shows the expected set without refreshing the browser.

Security and restrictions

Don't ignore the exhaust-deps rules just because the current version looks faster.