My dilemma involves retrieving specific product details based on the current slug displayed in the browser.
While I successfully retrieve all products using the following code:
export async function getAllProducts() {
const productData = await client.fetch('*[_type == "product"]');
return productData;
}
the problem arises when I attempt to retrieve products by slug, as the returned value is null:
export async function getProductBySlug(slug) {
const currentData = await client.fetch(
`*[_type == "product" && slug.current == '${slug}'][0]`
);
return currentData;
}
I'm scratching my head trying to figure out where I might be going wrong. Any insights?