Fetch Error - Cannot Read Property 'Map' of Null
categorybefore the fetch is done.
categoryis null, and your code will run top to bottom without waiting on the previous item (as JS is aync). So the fetch fires, but the rest is run immediately after while fetch is still waiting.
Before your return you can do something like
if ( category == null ) { return 'Loading...' }{category?.map(...)} and probably you need &&before
references(...)in the query
🤗
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.