State Management · Middle · Question 41 of 75
What does mutate(key) from useSWRConfig do?
- ✓Correct answer: Revalidates (and optionally updates) the cached data for that key everywhere
- 2Deletes the key from the server
- 3Changes the fetcher function for that key
Explanation
After a POST you call mutate('/api/todos') so every component using that key refetches. You can also pass new data to update the cache immediately, and the bound mutate from useSWR updates its own key.