Best Way to Fetch Global Data with GROQ and Next.js
_app.jsnot good practice? That's what I've been doing to fetch my
siteSettingssingleton (site name, og:image, nav items, etc), which feeds it into each page.
getInitialProps, then I would say, no. Or perhaps, it depends. See https://nextjs.org/docs/advanced-features/custom-app for some caveats.
IfgetServerSidePropsorgetInitialPropsis present in a page, Next.js will switch to render the page on-demand, per-request (meaning Server-Side Rendering ).
getInitialPropsseems to work fine with SSG (next build & export) for me
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.