I have a [slug].js page where I'm using getStaticPath
and getStaticProps
to fetch the data and create static page{
export async function getStaticProps({ params }) {
const { posts } = await hygraph.request(
`
query BlogPostPage($slug: String!){
posts(where:{slug: $slug}){
id
slug
title
tags
}
}
`,
{
slug: params.slug,
}
);
return {
props: {
posts,
},
};
}
export async function getStaticPaths() {
const { posts } = await hygraph.request(`
{
posts {
slug
}
}
`);
return {
paths: posts.map(({ slug }) => ({
params: { slug },
})),
fallback: false,
};
}
const Post = ({ posts }) => {
return (
<>
<div className='max-w-[1240px] mx-auto mt-3 px-4 lg:flex'>
<BlogPost posts={posts} />
<div className='lg:ml-3 mb-5'>
<div className='lg:sticky lg:top-[74px]'>
<SuggesCard />
</div>
</div>
</div>
</>
)
}
There are two react components: BlogPost
and SuggesCard
, I am sending fetched posts content to BlogPost
but now I want to fetch all the other post titles related to this fetched posts tag. so for this should i make another api call using getStaticPaths/getStaticProps
or should I use a different approach?