@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.
Files changed (37) hide show
  1. package/build/cjs/createFormFactory.js +2 -3
  2. package/build/cjs/createFormFactory.js.map +1 -1
  3. package/build/cjs/formContext.js.map +1 -1
  4. package/build/cjs/index.js +1 -2
  5. package/build/cjs/index.js.map +1 -1
  6. package/build/cjs/useField.js +46 -11
  7. package/build/cjs/useField.js.map +1 -1
  8. package/build/cjs/useForm.js +6 -4
  9. package/build/cjs/useForm.js.map +1 -1
  10. package/build/esm/index.js +47 -22
  11. package/build/esm/index.js.map +1 -1
  12. package/build/stats-html.html +1 -1
  13. package/build/stats-react.json +97 -153
  14. package/build/types/form-core/src/FieldApi.d.ts +2 -1
  15. package/build/types/form-core/src/FormApi.d.ts +2 -2
  16. package/build/types/form-core/src/utils.d.ts +7 -1
  17. package/build/types/index.d.ts +30 -22
  18. package/build/types/react-form/src/createFormFactory.d.ts +2 -3
  19. package/build/types/react-form/src/formContext.d.ts +8 -2
  20. package/build/types/react-form/src/index.d.ts +2 -4
  21. package/build/types/react-form/src/useField.d.ts +23 -8
  22. package/build/types/react-form/src/useForm.d.ts +2 -3
  23. package/build/umd/index.development.js +58 -32
  24. package/build/umd/index.development.js.map +1 -1
  25. package/build/umd/index.production.js +2 -2
  26. package/build/umd/index.production.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/createFormFactory.ts +4 -5
  29. package/src/formContext.ts +4 -1
  30. package/src/index.ts +2 -5
  31. package/src/useField.tsx +138 -0
  32. package/src/useForm.tsx +7 -6
  33. package/build/cjs/Field.js +0 -54
  34. package/build/cjs/Field.js.map +0 -1
  35. package/build/types/react-form/src/Field.d.ts +0 -9
  36. package/src/Field.tsx +0 -36
  37. 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
- }