Open History to see the last commit
1import React from 'react'
2import { useFieldContext } from './contexts.lib'
3import type { FunctionComponent } from 'react'
4β
5type AnyFieldComponent = (props: any) => React.ReactNode
6β
7export function wrapField(
8 Component: AnyFieldComponent,
9 fieldPropKey: string,
10): AnyFieldComponent {
11 const Wrapper: FunctionComponent<any> = function TanStackFormFieldWrapper(
12 props,
13 ) {
14 const field = useFieldContext()
15β
16 const newProps = { ...props, [fieldPropKey]: field }
17β
18 return <Component {...newProps} />
19 }
20β
21 Wrapper.displayName = 'TanStackForm.FieldComponent'
22β
23 return Wrapper as never
24}
25β
26export function brandComponentFactory(): (
27 component: AnyFieldComponent,
28) => AnyFieldComponent {
29 return (component) => component
30}