Contrast in "apollo-client in next.js" approaches chosen in next-with-apollo
npm library and the approach shown in next.js docs.
The link of approach chosen by next.js for apollo client: https://github.com/vercel/next.js/blob/canary/examples/with-apollo/lib/apolloClient.js
In next.js doc approach:
Some cons in next-with-apollo
approach
It made me really curious to see many are using next-with-apollo
and rarely seen the usage of the approach shown in next.js docs? I'm curious whether approach in next.js docs has any drawbacks (which i strong think of not having any)?
So which is better for both client-side data fetching and server-data fetching to support both CSR and SRR?
I found the answer by posting in next.js community:
Here it goes:
next.js doc's apollo examples avoid using getDataFromTree because it traverses the react tree twice in order to trigger all the queries and collect their result afterwards.
The drawback of using the approach on the next.js doc's apollo examples is since you don't use
getDataFromTree
, you have no way to know which queries your inner components are using. So you need to remember to prefetch everything you need ongetStaticProps
/getServerSideProps
and match the exact same queries/variablesnext.js doc's apollo examples way is recommended instead of
getInitialProps
so I would always use them unless one has some very specific reason not to
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With