how can I prefetch infinite query in getServerSideProps in next.js? #4031
Unanswered
killerdroid99
asked this question in
Q&A
Replies: 1 comment
-
you'd have to be more precise on what the issue is ... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am implementing pagination and having trouble to cache the infinite query (idk if it is even possible)
getServerSideProps is as follows...
`
export const getServerSideProps: GetServerSideProps = async (context) => {
const queryClient = new QueryClient()
await queryClient.prefetchInfiniteQuery(
["posts"],
async ({ pageParam = "" }) => {
const res = await fetch(
${ process.env.NEXT_PUBLIC_API }/api/posts?limit=${15}&cursor=${pageParam}
)
return await res.json()
}
)
return {
props: {
dehydratedState: dehydrate(queryClient),
},
}
}
`
Beta Was this translation helpful? Give feedback.
All reactions