TanStackT
TanStack2y ago
5 replies
afraid-moccasin

Equivalent for query v4

Hi all in the doc of router to use tanstack query with router we got this example :
const postsQueryOptions = queryOptions({
  queryKey: ['posts'],
  queryFn: () => fetchPosts(),
})
export const Route = createFileRoute('/posts')({
  // Use the `loader` option to ensure that the data is loaded
  loader: () => queryClient.ensureQueryData(postsQueryOptions),
  component: () => {
    // Read the data from the cache and subscribe to updates
    const posts = useSuspenseQuery(postsQueryOptions)
    return (
      <div>
        {posts.map((post) => (
          <Post key={post.id} post={post} />
        ))}
      </div>
    )
  },
})

Is there an equivalent of use case but with the V4 of Query as the queryOptions is a feature of the V5 and i can't upgrade to v5 due to client project restriction
Was this page helpful?