State Management · Middle · Question 42 of 75
Why do two components with the same SWR key make only one request?
- ✓Correct answer: SWR deduplicates requests with the same key within
dedupingInterval - 2The second component waits for the first to unmount
- 3SWR caches responses in
localStoragebetween components
Explanation
Within the deduping interval (2 seconds by default) concurrent requests for one key are merged, and both components share the cached data. That lets you call useUser() in many components freely.