A React hook that provides a client that subscribes to changes in your application,
A Sanity client
This hook is intended for advanced use cases and special API calls that the React SDK does not yet provide hooks for. We welcome you to get in touch with us to let us know your use cases for this!
function MyComponent() { const client = useClient({apiVersion: '2024-11-12'}) const [document, setDocument] = useState(null) useEffect(async () => { const doc = client.fetch('*[_id == "myDocumentId"]') setDocument(doc) }, []) return <div>{JSON.stringify(document) ?? 'Loading...'}</div>} Copy
function MyComponent() { const client = useClient({apiVersion: '2024-11-12'}) const [document, setDocument] = useState(null) useEffect(async () => { const doc = client.fetch('*[_id == "myDocumentId"]') setDocument(doc) }, []) return <div>{JSON.stringify(document) ?? 'Loading...'}</div>}
A React hook that provides a client that subscribes to changes in your application,