I'm getting a warning when using the sanity CMS to retrieve data from the back end.
Here is my Code:
client.js
import sanityClient from "@sanity/client";
import imageUrlBuilder from "@sanity/image-url";
const client = sanityClient({
projectId: "productKeyHidden",
dataset: "production",
apiVersion: "2022-03-10",
useCdn: true,
token:process.env.TOKEN,
});
const builder = imageUrlBuilder(client);
export const urlFor = (source) => {
return builder.image(source);
}
Home.js
import { View, Image } from 'react-native';
import React, { useEffect, useState } from 'react';
import client from '../client';
import { urlFor } from '../client';
import styles from '../styles';
export default function Home(){
const [uploads, setUploads] = useState([]);
const getImage = async () => {
const query = `*[_type == 'upload']`
const uploads = await client.fetch(query);
setUploads(uploads);
}
useEffect(() => {
getImage();
}, [])
return (
<View>
{uploads.map(
upload => <Image source={urlFor(upload.image)} />}
</View>
)
}
It isn't retrieving the data but sometimes gives me the error destroy is not a function
How to fix it?
EDIT: forgot to put the urlFor() function while posting this. but anyways the error still remains