@sanity/sdk-react 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -456,6 +456,74 @@ export function MultiProjectApp() {
456
456
 
457
457
  ---
458
458
 
459
+ ### Using the SDK inside Sanity Studio
460
+
461
+ The SDK can be embedded directly inside a Sanity Studio with zero manual configuration. Sanity Studio provides `SDKStudioContext` automatically, so `SanityApp` derives `projectId`, `dataset`, and auth from the Studio's workspace without any setup.
462
+
463
+ #### Zero-config setup (recommended)
464
+
465
+ Sanity Studio automatically provides `SDKStudioContext` to SDK components, so your SDK component needs no `config` prop at all:
466
+
467
+ ```tsx
468
+ import {SanityApp} from '@sanity/sdk-react'
469
+
470
+ // Inside a Sanity Studio — no config needed:
471
+ function MyStudioTool() {
472
+ return (
473
+ <SanityApp fallback={<div>Loading...</div>}>
474
+ <MyComponent />
475
+ </SanityApp>
476
+ )
477
+ }
478
+ ```
479
+
480
+ Under the hood, the Studio wraps its component tree with `SDKStudioContext.Provider`, passing its workspace to the SDK:
481
+
482
+ ```tsx
483
+ import {SDKStudioContext} from '@sanity/sdk-react'
484
+ import {useWorkspace} from 'sanity'
485
+
486
+ // This is done automatically by Sanity Studio — shown here for reference only
487
+ function StudioSDKWrapper({children}) {
488
+ const workspace = useWorkspace()
489
+ return <SDKStudioContext.Provider value={workspace}>{children}</SDKStudioContext.Provider>
490
+ }
491
+ ```
492
+
493
+ #### Explicit config takes precedence
494
+
495
+ If you pass a `config` prop to `SanityApp`, this config will take precedence over any workspace config picked up by `SDKStudioContext`:
496
+
497
+ ```tsx
498
+ // This uses the explicit config, not the Studio workspace
499
+ <SanityApp config={{projectId: 'other-project', dataset: 'staging'}} fallback={<Loading />}>
500
+ <MyComponent />
501
+ </SanityApp>
502
+ ```
503
+
504
+ #### Reactive auth token sync
505
+
506
+ If the Studio provides a reactive token source via `workspace.auth.token`, the SDK subscribes to it and stays in sync automatically. The Studio remains the single authority for auth — the SDK does not perform its own token refresh.
507
+
508
+ For older Studios that don't expose a token source, the SDK falls back to discovering the auth token from `localStorage` or cookie auth.
509
+
510
+ #### Migrating from `studioMode`
511
+
512
+ The `studioMode` config field is deprecated. If you are currently using it, the recommended replacement is to use the zero-config `SDKStudioContext` approach described above — which requires no `config` prop at all.
513
+
514
+ If you need to pass an explicit config, replace `studioMode` with `studio`:
515
+
516
+ ```diff
517
+ const config: SanityConfig = {
518
+ projectId: 'my-project',
519
+ dataset: 'production',
520
+ - studioMode: { enabled: true },
521
+ + studio: {},
522
+ }
523
+ ```
524
+
525
+ ---
526
+
459
527
  ### TypeScript & TypeGen
460
528
 
461
529
  ```bash