Issue with retrieving data from an array in a document in Sanity.io

11 replies
Last updated: Oct 4, 2021
pls urgent assistant needed thanks🙏
AI Update

I can see you need urgent help, but your question doesn't include any details about what issue you're facing with Sanity! To help you quickly and effectively, I need to know what problem you're trying to solve.

Please share:

  • What you're trying to accomplish
  • Any error messages you're seeing
  • What you've already tried
  • Relevant code snippets if applicable

In the meantime, here are quick resources for urgent help:

Common urgent issues and quick fixes:

  1. Studio won't start? Check you're using Node.js 20+ for Studio v4
  2. Build errors? Try npm install or clear your .sanity folder
  3. Can't see content? Verify your API token has correct permissions
  4. CORS errors? Add your domain in sanity.io/manage under API settings
  5. Deployment issues? Run sanity deploy from your Studio directory

Reply with specific details about your issue, and I'll provide targeted help immediately!

Hi Victor, could you try publishing your document to see if that gives you data? You may not be able to read unpublished data if you're using an unauthenticated client.
If that's not the issue, could you share the relevant query?
ok thanks
am getting the other items except the images array that is showing empty object
export default {  name: "home",
  title: "Home",
  type: "document",
  fields: [
    {
      name: "banner",
      title: "Banner ",
      type: "string",
    },
    {
      name: "title",
      title: "Banner Title",
      type: "string",
    },
    {
      name: "description",
      title: "Banner Description",
      type: "string",
    },
    {
      name: "images",
      title: "Images",
      type: "array",
      of: [
        {
          name: "image",
          type: "image",
        },
      ],
    },
    {
      name: "weddingDate",
      title: "Wedding Date",
      type: "date",
      options: {
        dateFormat: "YYYY-MM-DD",
        calendarTodayLabel: "Today",
      },
    },
  ],
};
useEffect(() => {    sanityClient
      .fetch(
        
*[_type == "home"]{
        title,
        weddingDate,
        description,
        images{
          asset ->{
            _id,
            url
          },
        },
  
      }
      )
      .then((data) => setSlide(data))
      .catch(console.error);
  }, []);
Hi Victor. Since
images
is an array, could you try appending
[]
in your query?

`*[_type == "home"]{
  title,
  weddingDate,
  description,
  images[]{
    asset->{
    // ...
`
thanks very much... you made my day❤️
Glad you got things working, Victor. 🙂
i dont know why am having this error
Error: Objects are not valid as a React child (found: object with keys {_key, _type, children, markDefs, style}). If you meant to render a collection of children, use an array instead.
useEffect(() => {    sanityClient
      .fetch(
        
*[_type == "home"]{
        title,
        weddingDate,
        description,
        coupleHighlight,
        bannerImages[]{
          asset ->{
            _id,
            url
          },
        },
       
        coupleIntroImage[]{
          asset ->{
            _id,
            url
          },
        },
        coupleIntroDescription,
      }
      )
      .then((data) => setSlide(data))
      .catch(console.error);
  }, []);

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.

Was this answer helpful?