I am fairly new to sanity. I just want to know how to connect it to a react native project using expo.
I tried adding 'exp://192.168.1.23:19000' in sanity's Cors. But it didn't accept 'exp://'
is there a way to add an expo project in sanity Cors?
Home.js
import React from 'react';
import client from '../client';
import { urlFor } from '../client';
export const getData = async () => {
const query = `*[_type == "upload"]`
const uploads = await client.fetch(query);
return{
props: { uploads }
}
}
export const Test = ({ upload: { image } }) => {
return(
<Image
source={urlFor(image)}
style={{
height: 250,
width: 250
}}
/>
);
}
const Home = ({ uploads }) => {
return (
<SafeAreaView>
<View style={{ flex:1, justifyContent: "center", alignContent: "center" }}>
{uploads?.map(
(upload) => <Test key={upload._id} upload={upload} />
)}
</View>
</SafeAreaView>
)
}
export default Home;
client.js
import sanityClient from "@sanity/client";
import imageUrlBuilder from "@sanity/image-url";
const client = sanityClient({
projectId: "myProjectId",
dataset: "production",
apiVersion: "2022-03-10",
useCdn: true,
token: "myToken",
});
// All the fields that dont have the required value like 'myToken', I just removed them for security reasons
const builder = imageUrlBuilder(client);
export const urlFor = (source) => builder.image(source);