Skip to content

Commit

Permalink
refactor(core): move GetFormValueContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 2b46b43 commit 3dc7e62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
13 changes: 13 additions & 0 deletions packages/sanity/src/_singletons/form/GetFormValueContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type {Path} from '@sanity/types'
import {createContext} from 'react'

/**
* @internal
* @hidden
*/
export type GetFormValueContextValue = (path: Path) => unknown

/**
* @internal
*/
export const GetFormValueContext = createContext<GetFormValueContextValue | null>(null)
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './field/diff/DocumentChangeContext'
export * from './form/DocumentIdContext'
export * from './form/FormBuilderContext'
export * from './form/FormValueContext'
export * from './form/GetFormValueContext'
11 changes: 2 additions & 9 deletions packages/sanity/src/core/form/contexts/GetFormValue.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import {type Path} from '@sanity/types'
import {createContext, type ReactNode, useCallback, useContext, useRef} from 'react'
import {type ReactNode, useCallback, useContext, useRef} from 'react'
import {GetFormValueContext} from 'sanity/_singletons'

import {getValueAtPath} from '../../field'
import {type FormDocumentValue} from '../types'

/**
* @internal
* @hidden
*/
export type GetFormValueContextValue = (path: Path) => unknown

const GetFormValueContext = createContext<GetFormValueContextValue | null>(null)

/**
*
* @internal
Expand Down

0 comments on commit 3dc7e62

Please sign in to comment.