Issue with retrieving data from an array in a document in Sanity.io
11 replies
Last updated: Oct 4, 2021
V
pls urgent assistant needed thanks🙏
Sep 28, 2021, 12:46 PM
P
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?
If that's not the issue, could you share the relevant query?
Sep 28, 2021, 2:26 PM
V
ok thanks
Sep 28, 2021, 2:59 PM
V
am getting the other items except the images array that is showing empty object
Sep 28, 2021, 3:01 PM
V
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",
},
},
],
};
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",
},
},
],
};
Sep 28, 2021, 3:01 PM
V
useEffect(() => { sanityClient
.fetch(
)
.then((data) => setSlide(data))
.catch(console.error);
}, []);
.fetch(
*[_type == "home"]{ title, weddingDate, description, images{ asset ->{ _id, url }, }, }
.then((data) => setSlide(data))
.catch(console.error);
}, []);
Sep 28, 2021, 3:02 PM
Hi Victor. Since
imagesis an array, could you try appending
[]in your query?
`*[_type == "home"]{ title, weddingDate, description, images[]{ asset->{ // ... `
Sep 28, 2021, 4:56 PM
V
thanks very much... you made my day❤️
Sep 29, 2021, 9:51 AM
V
i dont know why am having this error
Oct 4, 2021, 2:08 PM
V
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.
Oct 4, 2021, 2:08 PM
V
useEffect(() => { sanityClient
.fetch(
)
.then((data) => setSlide(data))
.catch(console.error);
}, []);
.fetch(
*[_type == "home"]{ title, weddingDate, description, coupleHighlight, bannerImages[]{ asset ->{ _id, url }, }, coupleIntroImage[]{ asset ->{ _id, url }, }, coupleIntroDescription, }
.then((data) => setSlide(data))
.catch(console.error);
}, []);
Oct 4, 2021, 2:09 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.