I am trying to perform a very basic search query with Sanity CMS.
This is how the person
schema I've created looks like:
export default {
title: "Person",
name: "person",
type: "document",
fields: [
{
title: "Name",
name: "name",
type: "string",
}
]
}
I have entered two different Person data. And this is how I try to fetch the data:
const client = sanityClient({
projectId: 'siaj5ql4',
dataset: 'production',
useCdn: true
})
const query = '*[_type == "person"]'
client.fetch(query).then(person => {
console.log(person)
})
But I get an empty array like so in the console: []
There is no error or anything.
Any ideas on this simple task?
In this article, we will use Sanity CMS as our data repository. Sanity treats content like data and offers a concise number of features to manage images ( Image Pipeline ), text ( Portable Text ), and design, all with the goal of taking a structured approach to content that improves web app performance.
Developers can use Sanity CMS with Gatsby to decrease build time and optimize web performance through a programmable modern platform that treats content like data. LogRocket is a frontend application monitoring solution that lets you replay problems as if they happened in your own browser.
A way that tells Next how to connect to Sanity and retrieve data. We do this with one of the additional dependencies we installed. Create a file called sanityClient.js in the root of your Next project (ideally in a lib or utils folder) and add this to it: Your projectId can be found in the sanity.json file in your Sanity project directory.
Like Commerce.js, Sanity.io is a headless provider. Sanity makes it easy to customise structured content, tailor it for a given format, and display it on any front-end. This includes custom input fields and different kinds of pages templates.
There are two common reasons for this:
Also note that the CDN can not be used with private datasets and/or access token.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With