Skip to content

Commit

Permalink
refactor(core): move ReferenceInputOptionsContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 6a02f80 commit 19311e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createContext} from 'react'
import type {ReferenceInputOptions} from 'sanity'

/**
* @internal
*/
export const ReferenceInputOptionsContext = createContext<ReferenceInputOptions>({})
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './form/inputs/ReferenceInput/ReferenceItemRefContext'
export * from './form/studio/DocumentFieldActionsContext'
export * from './form/studio/FormCallbacksContext'
export * from './form/studio/PresenceContext'
export * from './form/studio/ReferenceInputOptionsContext'
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import {type Path} from '@sanity/types'
import {
type ComponentType,
createContext,
type HTMLProps,
type ReactNode,
useContext,
useMemo,
} from 'react'
import {type ComponentType, type HTMLProps, type ReactNode, useContext, useMemo} from 'react'
import {ReferenceInputOptionsContext} from 'sanity/_singletons'

import {type TemplatePermissionsResult} from '../../../store'

const Context = createContext<ReferenceInputOptions>({})

/** @internal */
export interface TemplateOption {
id: string
Expand Down Expand Up @@ -66,7 +58,7 @@ export interface ReferenceInputOptions {
* @internal
*/
export function useReferenceInputOptions() {
return useContext(Context)
return useContext(ReferenceInputOptionsContext)
}

/**
Expand All @@ -93,5 +85,9 @@ export function ReferenceInputOptionsProvider(
[activePath, EditReferenceLinkComponent, onEditReference, initialValueTemplateItems],
)

return <Context.Provider value={contextValue}>{children}</Context.Provider>
return (
<ReferenceInputOptionsContext.Provider value={contextValue}>
{children}
</ReferenceInputOptionsContext.Provider>
)
}

0 comments on commit 19311e4

Please sign in to comment.