Prefetch query with parameters
I have a
page.tsx
that calls a function.
What if the getPosts call here, is subject to the params in the query string of the user landing on the page? Say "category" is a filter and I want to only show those.
Throws an error because now I am calling this function in the first render server side. It gives:
So what is the pattern that should be used here?2 Replies
ratty-blush•2mo ago
seems like you are using Next? In that case prefetch query in server component then handle user interaction separately.
continuing-cyan•2mo ago
You add it to query key itself
https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
Add all the filtering, sorting, searching to query key