Skip to content

Commit

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

/**
* @internal
*/
export const FormValueContext = createContext<FormValueContextValue | 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 @@ -7,3 +7,4 @@ export * from './field/diff/DiffContext'
export * from './field/diff/DocumentChangeContext'
export * from './form/DocumentIdContext'
export * from './form/FormBuilderContext'
export * from './form/FormValueContext'
5 changes: 2 additions & 3 deletions packages/sanity/src/core/form/contexts/FormValue.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {type Path} from '@sanity/types'
import {pathFor} from '@sanity/util/paths'
import {createContext, type ReactNode, useContext, useMemo} from 'react'
import {type ReactNode, useContext, useMemo} from 'react'
import {FormValueContext} from 'sanity/_singletons'

import {getValueAtPath} from '../../field'
import {type FormDocumentValue} from '../types'
Expand All @@ -13,8 +14,6 @@ export interface FormValueContextValue {
value: FormDocumentValue | undefined
}

const FormValueContext = createContext<FormValueContextValue | null>(null)

/**
*
* @internal
Expand Down

0 comments on commit 2b46b43

Please sign in to comment.