unload()
A new API to clear the SWR cache
Usage
Import it for global or use as scoped case
import { unload } from 'swr' // clears the default cache
const { unload } = useSWRConfig() // clears the current provider's cache
Call it to clear the cache
unload() // clear + revalidate mounted hooks
unload({ revalidate: false }) // clear only, e.g. logout before navigating away
Difference from mutate(filter, undefined): Deletes every cache entry (including $inf$/$sub$ keys that mutate(() => true) can't cover), discards in-flight requests (FETCHES, PRELOAD etc....), re-renders mounted hooks, and revalidates them by default — pass { revalidate: false } to skip refetching (e.g. logout).
unload()
Usage
Import it for global or use as scoped case
Call it to clear the cache
Difference from
mutate(filter, undefined): Deletes every cache entry (including$inf$/$sub$keys thatmutate(() => true)can't cover), discards in-flight requests (FETCHES,PRELOADetc....), re-renders mounted hooks, and revalidates them by default — pass{ revalidate: false }to skip refetching (e.g. logout).