A name filter uses useMemo to recompute only when the search query changes. A separate counter button is unrelated to the filter.
Click the counter button — the filter run count goes up even though the search query never changed. The memo is recomputing when it shouldn't.
useMemo recomputes whenever any value in its dependency array changes — are all listed dependencies actually used inside it?
useMemo recomputes whenever any value in its dependency array changes — are all listed dependencies actually used inside it?
Why this fixes it
count was listed in the dependency array but is never read inside the useMemo callback — only query is used. Every button click updated count, which invalidated the memo and triggered an unnecessary recompute. Removing count from the dependency array means the memo only reruns when query actually changes, which is the only value the filter depends on.