
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeCongrats on upgrading to v3! The good news is that in Sanity v3, you still use @sanity/client to fetch data, but you'll import createClient instead of the old sanityClient export.
First, install the client library:
npm install @sanity/clientIn v3, you use createClient from @sanity/client:
import { createClient } from '@sanity/client'
export const client = createClient({
projectId: 'your-project-id', // find this in sanity.json or your Studio
dataset: 'production', // or your dataset name
useCdn: true, // set to false if you need fresh data
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})Once you have your client configured, you can fetch data using GROQ queries:
import { client } from './client' // wherever you created your client
// In your React component
function MyComponent() {
const [data, setData] = React.useState(null)
React.useEffect(() => {
client.fetch('*[_type == "post"]').then((posts) => {
setData(posts)
})
}, [])
if (!data) return <div>Loading...</div>
return (
<div>
{data.map((post) => (
<div key={post._id}>{post.title}</div>
))}
</div>
)
}createClient instead of the default exportapiVersion parameter is now required (use a current date in YYYY-MM-DD format).fetch(), .create(), .patch(), etc.The React single-page application guide might also be helpful, though it may reference some patterns you can adapt for vanilla React with React Router.
Hope this gets you up and running! 🚀
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store