Working on a react native project, I m trying to fetch data from sanity, but I get this error ‘no query’, I double checked the projectId, the dataset name, I tried the query in the vision section of sanity studio and it works, the dataset is public.
Sanity.js
import { createClient } from "@sanity/client";
import imageUrlBuilder from "@sanity/image-url";
const client = createClient({
projectId: '18drtz8q',
dataset: 'production',
useCdn: true,
apiVersion: 'v2022-07-03',
});
const builder = imageUrlBuilder(client);
export const urlFor = (source) => builder.image(source);
export const getCategory = async () => {
const items = await client.fetch('*[_type == "category"]').then((data) => {
return data;
});
return items;
};
sanity.cli.js
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: '18drtz8q',
dataset: 'production',
}
})
Where I m trying to call the function to fetch data
const CategoryList = () => {
const [categories, setCategories] = useState(null)
const [isLoading, setisLoading] = useState(false)
useEffect(() => {
setisLoading(true)
getCategory()
.then((data) => setCategories(data))
.catch((err) => console.log(err));
setTimeout(() => setisLoading(false), 2000)
}, []);
...
I tried the same logic with react expo, and I was expecting the same results working with react native CLI
Oualid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.