Skip to content

initialData with placeholderData? #8251

Answered by TkDodo
J4v4Scr1pt asked this question in Q&A
Discussion options

You must be logged in to vote

When I read the docs I thought when I used it as a function it would be initiated only once when the query is initialized

that is what’s happening. but the queryKeys ['organizations', { filters: 'foo' }] and ['organizations', { filters: 'bar' }] are two different queries. So when you switch filters, you might create a new query if it does not exist, and then the initialData function runs.

We get the initial data on the server(RSC) with default filtering applied

The options are:

  • only set initialData when the filter equals the default filter
  • use <HydationBoundary> instead of initialData for SSR. This is very likely the better choice.

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@J4v4Scr1pt
Comment options

@TkDodo
Comment options

Answer selected by J4v4Scr1pt
@J4v4Scr1pt
Comment options

@TkDodo
Comment options

@J4v4Scr1pt
Comment options

@J4v4Scr1pt
Comment options

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