Im using Nextjs and I have a slice which creates an array of data from a customType in a slice using content relationship field.
I get the content relationship field data from slice
, but where i'm struggling is then querying data based on testimonial.id
inside the slice as I can't seem to use getStaticProps
in a slice, like I would in other components.
{
"variation": "default",
"version": "sktwi1xtmkfgx8626",
"items": [
{
"testimonial": {
"id": "ZZgprBEAAKUjpPat",
"type": "testimonials",
"tags": [],
"lang": "en-gb",
"slug": "-",
"first_publication_date": "2024-01-05T16:09:19+0000",
"last_publication_date": "2024-01-05T16:09:19+0000",
"link_type": "Document",
"isBroken": false
}
},
{
"testimonial": {
"id": "ZZgprBEAAKUjpPat",
"type": "testimonials",
"tags": [],
"lang": "en-gb",
"slug": "-",
"first_publication_date": "2024-01-05T16:09:19+0000",
"last_publication_date": "2024-01-05T16:09:19+0000",
"link_type": "Document",
"isBroken": false
}
}
],
"primary": {},
"id": "testimonial_carousel$61c8c74e-d0cc-4093-b7dc-b969fc48c020",
"slice_type": "testimonial_carousel",
"slice_label": null
}
What i want is to be able to query the testimonials custom type based on the IDs in the array from the slice, then display all returned data in the slice; title, author company etc.
In a page component I normal do something like this which would give me all the customtype data for each ID queried in featuredWork
:
export async function getServerSideProps({ previewData }: Index) {
const client = createClient({ previewData });
const page = await client.getSingle('homepage');
const getFeaturedWork = page.data.featured_work_list.map((work: DocumentSelect) => work.select.id);
const featuredWork = await client.getAllByIDs(getFeaturedWork);
return {
props: {
featuredWork,
},
};
}