mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-10 04:19:54 +00:00
fix: refactor to flat generics with consistent names & patterns
This commit is contained in:
@@ -3,17 +3,17 @@ id: useField
|
||||
title: useField
|
||||
---
|
||||
|
||||
### `UseField<TFormData>`
|
||||
### `UseField<TParentData>`
|
||||
|
||||
A type representing a hook for using a field in a form with the given form data type.
|
||||
|
||||
```tsx
|
||||
export type UseField = <TField extends DeepKeys<TFormData>>(
|
||||
export type UseField = <TField extends DeepKeys<TParentData>>(
|
||||
opts?: { name: TField } & FieldOptions<
|
||||
DeepValue<TFormData, TField>,
|
||||
TFormData
|
||||
DeepValue<TParentData, TField>,
|
||||
TParentData
|
||||
>,
|
||||
) => FieldApi<DeepValue<TFormData, TField>, TFormData>
|
||||
) => FieldApi<DeepValue<TParentData, TField>, TParentData>
|
||||
```
|
||||
|
||||
- A function that takes an optional object with a `name` property and field options, and returns a `FieldApi` instance for the specified field.
|
||||
@@ -21,31 +21,31 @@ export type UseField = <TField extends DeepKeys<TFormData>>(
|
||||
### `useField`
|
||||
|
||||
```tsx
|
||||
export function useField<TData, TFormData>(
|
||||
opts: FieldOptions<TData, TFormData>,
|
||||
): FieldApi<TData, TFormData>
|
||||
export function useField<TData, TParentData>(
|
||||
opts: FieldOptions<TData, TParentData>,
|
||||
): FieldApi<TData, TParentData>
|
||||
```
|
||||
|
||||
A hook for managing a field in a form.
|
||||
|
||||
- ```tsx
|
||||
opts: FieldOptions<TData, TFormData>
|
||||
opts: FieldOptions<TData, TParentData>
|
||||
```
|
||||
- An object with field options.
|
||||
|
||||
#### Returns
|
||||
|
||||
- ```tsx
|
||||
FieldApi<TData, TFormData>
|
||||
FieldApi<TData, TParentData>
|
||||
```
|
||||
- The `FieldApi` instance for the specified field.
|
||||
|
||||
### `createUseField`
|
||||
|
||||
```tsx
|
||||
export function createUseField<TFormData>(
|
||||
formApi: FormApi<TFormData>,
|
||||
): UseField<TFormData>
|
||||
export function createUseField<TParentData>(
|
||||
formApi: FormApi<TParentData>,
|
||||
): UseField<TParentData>
|
||||
```
|
||||
|
||||
A function that creates a `UseField` hook bound to the given `formApi`.
|
||||
|
||||
Reference in New Issue
Block a user