Skip to content
Discussion options

You must be logged in to vote

I don't need the cache on the server, so I'm ignoring the hydration method for this question.

That is not what the hydration method is doing though :) By using it, you create a "temporary" cache that has the correct structure that your queries will have. By dehydrating it, you'e sending the correct structure to the client. The cache is created inside getStaticProps every time, so it doesn't really cache anything:

export async function getStaticProps() {
   const queryClient = new QueryClient()
 
   await queryClient.prefetchQuery('posts', getPosts)
 
   return {
     props: {
       dehydratedState: dehydrate(queryClient),
     },
   }
 }

I still think this is the easiest way to prefet…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@bennettdams
Comment options

@bennettdams
Comment options

@bennettdams
Comment options

@cmacdonnacha
Comment options

@TkDodo
Comment options

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