Skip to content

reavalidateOnMount and revalidateIfStale #1400

Answered by shuding
burnoo asked this question in General

You must be logged in to vote

The revalidateOnMount option (default to undefined) is used to force override the SWR revalidation behavior on mounting. The new revalidateIfStale (default to true) means if SWR should revalidate on mounting if the cache exists.

So basically it works like this:

  1. A SWR hook mounts
  2. Is recalidateOnMount defined? Start request if it’s true, stop if false.
  3. Is there existing cache? If there isn’t, start the request.
  4. Is revalidateIfStale true? If it is, start the request.

Replies: 4 comments 8 replies

You must be logged in to vote
2 replies
@nandorojo

@shuding

Answer selected by burnoo

You must be logged in to vote
5 replies
@shuding

@dorgamliel1

@koba04

koba04 Jan 21, 2024
Collaborator

@marmotgary

@PaulMJL

You must be logged in to vote
1 reply
@sb007ty

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
10 participants