You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(react): update useDocument to return data (#510)
* refactor: update useDocument hook to return data under a `data` for consistency across the SDK
* fix: ensure useDocument hook returns an empty string as default for name
* fix: correct path parameter in useEditDocument hook for clarity
* Update 0-Migration-Guide.md
Co-authored-by: Cole Peters <[email protected]>
---------
Co-authored-by: Cole Peters <[email protected]>
console.log(product?.title) // product is possibly null
195
+
196
+
// Path selection - now returns {data: T | undefined}
197
+
const {data: title} =useDocument({
198
+
documentId: '123',
199
+
documentType: 'product',
200
+
path: 'title',
201
+
})
202
+
console.log(title) // title is possibly undefined
203
+
```
204
+
169
205
## Migrating to @sanity/sdk-react@0.0.0-rc.7
170
206
171
207
This version introduces significant improvements for TypeScript users by integrating [Sanity TypeGen](https://www.sanity.io/docs/sanity-typegen). While Typegen is optional, using it unlocks strong type safety for documents, queries, and projections. These changes also refine hook signatures for better consistency, even for JavaScript users.
0 commit comments