@tanstack/react-form 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/createFormFactory.js +2 -3
- package/build/cjs/createFormFactory.js.map +1 -1
- package/build/cjs/formContext.js.map +1 -1
- package/build/cjs/index.js +1 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/useField.js +46 -11
- package/build/cjs/useField.js.map +1 -1
- package/build/cjs/useForm.js +6 -4
- package/build/cjs/useForm.js.map +1 -1
- package/build/esm/index.js +47 -22
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +97 -153
- package/build/types/form-core/src/FieldApi.d.ts +2 -1
- package/build/types/form-core/src/FormApi.d.ts +2 -2
- package/build/types/form-core/src/utils.d.ts +7 -1
- package/build/types/index.d.ts +30 -22
- package/build/types/react-form/src/createFormFactory.d.ts +2 -3
- package/build/types/react-form/src/formContext.d.ts +8 -2
- package/build/types/react-form/src/index.d.ts +2 -4
- package/build/types/react-form/src/useField.d.ts +23 -8
- package/build/types/react-form/src/useForm.d.ts +2 -3
- package/build/umd/index.development.js +58 -32
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/createFormFactory.ts +4 -5
- package/src/formContext.ts +4 -1
- package/src/index.ts +2 -5
- package/src/useField.tsx +138 -0
- package/src/useForm.tsx +7 -6
- package/build/cjs/Field.js +0 -54
- package/build/cjs/Field.js.map +0 -1
- package/build/types/react-form/src/Field.d.ts +0 -9
- package/src/Field.tsx +0 -36
- package/src/useField.ts +0 -50
package/src/useField.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
//
|
|
3
|
-
import { useStore } from '@tanstack/react-store'
|
|
4
|
-
import type { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core'
|
|
5
|
-
import { FieldApi } from '@tanstack/form-core'
|
|
6
|
-
import { useFormContext } from './formContext'
|
|
7
|
-
import type { FormFactory } from './createFormFactory'
|
|
8
|
-
|
|
9
|
-
declare module '@tanstack/form-core' {
|
|
10
|
-
// eslint-disable-next-line no-shadow
|
|
11
|
-
interface FieldOptions<TData, TFormData> {
|
|
12
|
-
formFactory?: FormFactory<TFormData>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(
|
|
17
|
-
opts?: { name: TField } & FieldOptions<
|
|
18
|
-
DeepValue<TFormData, TField>,
|
|
19
|
-
TFormData
|
|
20
|
-
>,
|
|
21
|
-
) => FieldApi<DeepValue<TFormData, TField>, TFormData>
|
|
22
|
-
|
|
23
|
-
export function createUseField<TFormData>(): UseField<TFormData> {
|
|
24
|
-
return (opts) => {
|
|
25
|
-
return useField(opts as any)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function useField<TData, TFormData>(
|
|
30
|
-
opts: FieldOptions<TData, TFormData> & {
|
|
31
|
-
// selector: (state: FieldApi<TData, TFormData>) => TSelected
|
|
32
|
-
},
|
|
33
|
-
): FieldApi<TData, TFormData> {
|
|
34
|
-
// Get the form API either manually or from context
|
|
35
|
-
const formApi = useFormContext()
|
|
36
|
-
|
|
37
|
-
const [fieldApi] = React.useState<FieldApi<TData, TFormData>>(
|
|
38
|
-
() => new FieldApi({ ...opts, form: formApi }),
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
// Keep options up to date as they are rendered
|
|
42
|
-
fieldApi.update({ ...opts, form: formApi })
|
|
43
|
-
|
|
44
|
-
useStore(fieldApi.store)
|
|
45
|
-
|
|
46
|
-
// Instantiates field meta and removes it when unrendered
|
|
47
|
-
React.useEffect(() => fieldApi.mount(), [fieldApi])
|
|
48
|
-
|
|
49
|
-
return fieldApi
|
|
50
|
-
}
|