Can I use the same Sanity data on multiple React projects?
Good news - you don't need to set up Sanity again! You can absolutely access the same Sanity data from multiple React projects. You have a couple of options:
Option 1: Install the Sanity Client (Recommended)
Install the @sanity/client package in your second React project:
npm install @sanity/clientThen create a client with your existing project's credentials:
import { createClient } from '@sanity/client'
const client = createClient({
projectId: 'your-project-id', // same as your first project
dataset: 'production', // same dataset
apiVersion: '2024-01-01',
useCdn: true, // use CDN for faster reads
})
// Query your data
const posts = await client.fetch('*[_type == "post"]')You're just connecting to the same Content Lake from a different application - no need to duplicate anything!
Option 2: Direct HTTP API Calls
If you prefer not to install the Sanity client, you can make direct HTTP requests to the Query API:
const projectId = 'your-project-id'
const dataset = 'production'
const query = encodeURIComponent('*[_type == "post"]')
const url = `https://${projectId}.api.sanity.io/v2024-01-01/data/query/${dataset}?query=${query}`
const response = await fetch(url)
const data = await response.json()Important: If your dataset is private, you'll need to include authentication. The Sanity client handles this automatically if you provide a token.
Which Option to Choose?
Use the Sanity client - it's easier, handles authentication automatically, provides better error handling, and includes helpful utilities. The direct HTTP approach works but requires more manual setup.
Both approaches access the exact same data from your Content Lake, so you can have as many frontend projects as you want all pulling from the same Sanity project!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.