Struggling to retrieve data from Sanity in Next.js, but encountering an error that reads: "Error: expected ']' following expression." As a beginner in this, I've been trying to troubleshoot it, but I'm unsure of the root cause of the error.
Below are my schemas for `product.ts`:
import {defineField, defineType} from 'sanity'
export default defineType({
name: 'product',
title: 'product',
type: 'document',
fields: [
// Define fields here
],
// Preview configuration
})
Schema for `category.ts`:
import {defineField, defineType} from 'sanity'
export default defineType({
name: 'category',
title: 'Category',
type: 'document',
fields: [
// Define fields for category
],
})
Using `client` and `groq` for fetching:
// Code for fetching products
// Code for fetching categories
Here is my product page layout:
// Code for product page
Layout for `product/[category]/page.tsx`:
// Code for category page
Defined interfaces for items and categories:
// Interfaces for items and categories
Seeking assistance with the error encountered. Thank you.
After some restructuring and modifying the codes, the issue was resolved. Success!