Skip to content

RFC: unload() #4297

Description

@huozhi

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions