Can I use SWR with GraphQL & inside the getStaticProps
method?
#726
Replies: 2 comments 3 replies
-
About how to use SWR with GraphQL. SWR is not GraphQL first as Apollo or Relay, but because the fetcher can be any async function you could use something like About Next.js data-fetching methods, you can't use SWR there because SWR is a Hook so it only runs inside the actual React components, but what you could totally do is to fetch the data you will need in those Next.js methods, pass them as props and use them as initialValue of SWR. Check the Usage with Next.js page in the docs for an example. |
Beta Was this translation helpful? Give feedback.
-
May someone has already built a project using GraphQL & the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am short of a beginner here, so I would like to ask if I can use the
useSWR
hook with my GraphQL API built with Apollo. I would not like to use the Apollo Client on the front-end, so I am interested in using Relay Modern. I have seen various articles and it says it also in the documentation that SWR works great with GraphQL. But does this means it works with a GraphQL API or just with thegraphql-request
package?Also, what should I do for fetching data inside the
getStaticProps
orgetServerSideProps
methods, provided by Next.js. Will this technique boost my performance, or is it not going to make any change. Or, should I only use it within a React.js component (most likely in theuseEffect()
hook)?Thank you in advance for your help or advice!
Beta Was this translation helpful? Give feedback.
All reactions