Skip to content

Commit

Permalink
refactor(core): move SourceContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 5db6f24 commit 896ed1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from './presence/FormFieldPresenceContext'
export * from './store/_legacy/ResourceCacheContext'
export * from './studio/ColorSchemeSetValueContext'
export * from './studio/ColorSchemeValueContext'
export * from './studio/SourceContext'
7 changes: 7 additions & 0 deletions packages/sanity/src/_singletons/studio/SourceContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createContext} from 'react'
import type {Source} from 'sanity'

/**
* @internal
*/
export const SourceContext = createContext<Source | null>(null)
5 changes: 2 additions & 3 deletions packages/sanity/src/core/studio/source.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {createContext, type ReactNode, useContext} from 'react'
import {type ReactNode, useContext} from 'react'
import {SourceContext} from 'sanity/_singletons'

import {type Source} from '../config'
import {useWorkspace} from './workspace'
Expand All @@ -8,8 +9,6 @@ export type SourceProviderProps =
| {source: Source; children?: ReactNode}
| {name: string; children?: ReactNode}

const SourceContext = createContext<Source | null>(null)

/** @internal */
export function SourceProvider({children, ...props}: SourceProviderProps) {
const parentSource = useContext(SourceContext)
Expand Down

0 comments on commit 896ed1e

Please sign in to comment.