How do you pre-fetch with getServerSideProps while using usePaginatedQuery? #2839
Unanswered
jmacdonagh
asked this question in
Q&A
Replies: 1 comment 2 replies
-
@jmacdonagh thanks for the thorough description and code! I think you are essentially doing this right except for one thing. You have So I think this change should resolve it for you -const queryKey = getQueryKey(getProjects)
+const queryKey = getQueryKey(getProjects, {skip: 0, take: 10}) Try that and report back. Could be something else amiss I haven't noticed. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is the proper way to pre-render a page that will use
usePaginatedQuery
? I've tried a few methods and the best I can come up with is sort of a hack. This page needs to be pre-rendered on each request so I'm usinggetServerSideProps
.I first tried pre-fetching using a
QueryClient
, although I wasn't sure if this was supported outside ofgetStaticProps
.This results in a runtime error "Error: A React component suspended while rendering, but no fallback UI was specified." So, the query didn't think it had some results to give me on the first pass.
If I don't allow suspense:
then I see the log message
"null"
on the server console (and never"results"
). The server isn't able to pre-render the page. So clearly pre-fetching isn't allowed here.I then tried fetching initial data and using the
initialData
option.This results in the same suspense runtime error.
The only way I've gotten this it work is a bit of a hack:
When I do this, I do not see
"null"
in the server console, it appears to get the results right away. I also never see"null"
on the client console.So this apparantly works, the client is given a pre-rendered page and it is able to properly paginate. However this seems like a hack. I'm relying on the behavior that the
usePaginatedQuery
withinitialData
andsuspense: false
won't actually return undefined.Am I going about this the wrong way?
For completeness, the query is defined as:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions