Hi. I'm a beginner working on my first project and I'm wondering how can I fetch data from my DIrectus repo project (it hasnt been deployed), and my Next 13.4 project?
It's a portfolio website containing products, within a 'products' collection.
I'd like to render all of the products within the collection by their slug.
Is this a good approach?
export default function Products({ products }) {
return (
<div>
{products.map((product) => (
<div key={product.id}>
<h1>Product: {product.name}</h1>
{/* Render other product details */}
</div>
))}
</div>
);
}
export async function getStaticProps() {
const directus = await getDirectusClient();
const response = await directus.items("products")
const formattedProducts = response.data.map((product) => {
return {
...product,
};
});
return {
props: {
products,
},
};
}
This code is from app/products/[slug]/page.tsx