usePrefetchQuery
The usePrefetchQuery does not return anything, it should be used just to fire a prefetch during render, before a suspense boundary that wraps a component that uses useSuspenseQuery.
import { usePrefetchQuery, queryOptions } from '@suspensive/react-query'
const PostPage = ({ postId }) => {
usePrefetchQuery(query.post(postId)) // Prefetch query before suspense boundary
return (
<Suspense fallback={<div>Loading...</div>}>
<Post postId={postId} />
</Suspense>
)
}
export const Post = ({ postId }) => {
const { data } = useSuspenseQuery(query.post(postId))
return (
<div>
<h1>{data.title}</h1>
<p>{data.body}</p>
</div>
)
}
const query = {
post: (postId) =>
queryOptions({
queryKey: ['posts', postId],
queryFn: () => getPost(postId),
}),
}