I'm using Next.js with Prismic and I was wondering if it's possible to query (server-side) data inside a slice, for example, if I have a slice that needs to get the amount of stars a certain GitHub repo has to then display it. If it's not possible to do that, how can I pass data I fetch on the index.js page, for example, and pass it down to every slice on the page? The SliceZone already has every prop being passed to it: <SliceZone {...props} resolver={resolver} />
But inside the slices I only have access to the slice object, I haven't access to anything that is passed down to the SliceZone.
I'd be happy to help you work through this. Could you share your project files with me, and let me know what you're trying to accomplish? You can send me your files in a DM as a ZIP file or git repo.
I am having trouble querying any documents outside the slicezone. I have a custom post type called tracks which I would like to query inside a nextjs component I am using this
export async function getStaticProps() {
const trackRes = await Client().query(Prismic.Predicates.at("document.type", "track"));
const artistRes = await Client().query(Prismic.Predicates.at("document.type", "artist"));
const tracks = trackRes.results;
const artists = artistRes.results;
console.log(tracks);
return {
props: {
tracks,
}, // will be passed to the page component as props
};
}
which is fine I can log the tracks to the console but I can not access them from within the component here is the full components code
I'm playing with this, and I have one initial question: does it work if you remove the function invocation, getStaticProps(), near the bottom of the component?
Let me know if not, and I'll keep trying to debug.
Sam
samlittlefair
(Sam Littlefair)
closed , flag & select 'Something Else' to reopen.
19
This thread has been closed due to inactivity. Flag to reopen.