State Management · Senior · Question 37 of 75
How does SWR avoid re-rendering a component when unrelated fields of the response change?
- ✓Correct answer: Dependency collection: a component re-renders only for the returned fields it actually reads
- 2It compares responses with
JSON.stringifyand never re-renders - 3It requires wrapping the component in
React.memo
Explanation
If a component uses only data, changes to isValidating don't re-render it. SWR also deep-compares data by default (compare option), so an identical refetch doesn't trigger an update.