State Management · Middle · Question 58 of 75
How do you make a component re-render only when one post from a cached list changes?
const { post } = useGetPostsQuery(undefined, {
selectFromResult: ({ data }) => ({ post: data?.find((p) => p.id === id) }),
});- ✓Correct answer: Use
selectFromResultto pick the needed part of the query result - 2Wrap the component in
memo - 3Call the endpoint once per post
Explanation
The hook compares the selected value shallowly and skips re-renders when it is unchanged. Return stable references from the selector.