react-query with Nextjs' getStaticProps #1365
Replies: 3 comments 2 replies
-
Same here. I tried everything but no luck. If you found something please let me @creativiii |
Beta Was this translation helpful? Give feedback.
-
If you can create an open source example that I can check out, I’m happy to take a look |
Beta Was this translation helpful? Give feedback.
-
The problem isn't actually caused by getStaticProps, but more by the way Next.js works nowadays. Pages are rendered both server and client side even if no server-side functions are defined, which causes Example without There are two solutions to this that I've been able to find:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've just started off with React Query but I'm finding myself confused on how I can use it to fetch data client side with Next.js.
A lot of my data fetching is dependant on the page I'm on, however both
useRouter
as well as passingcontext.params
are completely empty during the first render, which means If I try passing a value from the router that will beundefined
:In an app without
react-query
I would just fetch data insideuseEffect
and then map it to a state, however running useQuery inside ofuseEffect
is kind of pointless as I'll still need to dispatch its outcome to a normal state.What's the best approach to this situation? I'm very confused on how to get these two to work together nicely.
Edit: I've looked at the official next.js example, but it doesn't give a lot of help.
usePosts
seems to have anisClient
parameter, but it's undefined and unused in the hook 🤷♂️Any help would be greatly appreciated as I am even more confused than before.
Beta Was this translation helpful? Give feedback.
All reactions