TanStackT
TanStack2y ago
12 replies
brilliant-lime

Advanced SSR - is queryFn on the client redundant?

Hey there, I am trying to set up for my project that I have been working on ssr with tanstack/react-query and Next.js

Looking through the documentation, I found the following resource (https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr).

In my use case, I am implementing the app router, but what is confusing me is the code that is run on the client.

  function Posts() {
    const { data } = useQuery({ queryKey: ['posts'], queryFn: getPosts })  
  }


Why does the queryFn needs to be passed again on the client? The data is passed from the server, without having the query function set. (Example: https://codesandbox.io/p/devbox/gifted-colden-dgmk45, check the movie/Movies.tsx file).

Thank you in advance, hope my question is clear enough 🤠
Was this page helpful?