Skip to content
Discussion options

You must be logged in to vote

The problem here is that setQueryData seems to extend the lifetime of the data.

Two ways to address this:

  1. as you've said, you can pass updatedAt as options to setQueryData. It defaults to Date.now() because we assume that data that you write to the cache is from "now" at the time of writing. Using dataUpdatedAt from what is currently in the cache seems good.

  2. Usually, with optimistic updates, you'd just invalidate in onSettled. That makes sure that no matter what, at the end of your mutation, your entry is refetched from the server if it is currently used or marked as stale if it's unused so that it will be refetched when you mount it the next time.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sowizz
Comment options

@TkDodo
Comment options

Answer selected by Pumkko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants