Skip to content

Commit 8f2ffe9

Browse files
Merge branch 'main' into reset-field
2 parents fdb6348 + fed72ed commit 8f2ffe9

File tree

52 files changed

+792
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+792
-322
lines changed

CONTRIBUTING.md

+67-24
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,47 @@ If you are here to suggest a feature, first create an issue if it does not alrea
1717
If you have been assigned to fix an issue or develop a new feature, please follow these steps to get started:
1818

1919
- Fork this repository.
20-
- Install dependencies by running `$ pnpm install`.
21-
- We use [pnpm](https://pnpm.io/) v7 for package management.
22-
- We use [nvm](https://github.com/nvm-sh/nvm) to manage node versions - please make sure to use the version mentioned in `.nvmrc`.
23-
- Run development server using `pnpm run watch`.
20+
- Install dependencies
21+
22+
```bash
23+
pnpm install
24+
```
25+
26+
- We use [pnpm](https://pnpm.io/) v9 for package management (run in case of pnpm-related issues).
27+
28+
```bash
29+
corepack enable && corepack prepare
30+
```
31+
32+
- We use [nvm](https://github.com/nvm-sh/nvm) to manage node versions - please make sure to use the version mentioned in `.nvmrc`
33+
34+
```bash
35+
nvm use
36+
```
37+
38+
- Build all packages.
39+
40+
```bash
41+
pnpm build:all
42+
```
43+
44+
- Run development server.
45+
46+
```bash
47+
pnpm run watch
48+
```
49+
2450
- Implement your changes and tests to files in the `src/` directory and corresponding test files.
2551
- Document your changes in the appropriate doc page.
2652
- Git stage your required changes and commit (see below commit guidelines).
2753
- Submit PR for review.
2854

2955
### Editing the docs locally and previewing the changes
3056

31-
The documentations for all the TanStack projects are hosted on [tanstack.com](https://tanstack.com), which is a Remix application (https://github.com/TanStack/tanstack.com). You need to run this app locally to preview your changes in the `TanStack/form` docs.
57+
The documentations for all the TanStack projects are hosted on [tanstack.com](https://tanstack.com), which is a TanStack Start application (https://github.com/TanStack/tanstack.com). You need to run this app locally to preview your changes in the `TanStack/form` docs.
3258

3359
> [!NOTE]
34-
> The Remix app fetches the doc pages from GitHub in production, and searches for them at `../form/docs` in development. Your local clone of `TanStack/form` needs to be in the same directory as the local clone of `TansStack/tanstack.com`.
60+
> The website fetches the doc pages from GitHub in production, and searches for them at `../form/docs` in development. Your local clone of `TanStack/form` needs to be in the same directory as the local clone of `TansStack/tanstack.com`.
3561

3662
You can follow these steps to set up the docs for local development:
3763

@@ -85,13 +111,23 @@ https://github.com/fulopkovacs/form/assets/43729152/9d35a3c3-8153-4e74-9cb2-af27
85111

86112
### Running examples
87113

88-
- Make sure you've installed the dependencies by running `$ pnpm install` in the repo's root directory.
89-
- If you want to run the example against your local changes, run `pnpm run watch` in the repo's root directory. Otherwise, it will be run against the latest TanStack Form release.
90-
- Run `pnpm run dev` in the selected examples' directory.
114+
- Make sure you've installed the dependencies in the repo's root directory.
115+
116+
```bash
117+
pnpm install
118+
```
119+
120+
- If you want to run the example against your local changes, run below in the repo's root directory. Otherwise, it will be run against the latest TanStack Form release.
121+
122+
```bash
123+
pnpm run watch
124+
```
91125
92-
#### Note on `examples/react-native`
126+
- Run below in the selected examples' directory.
93127

94-
React Native example requires Expo to work. Please follow the instructions from example's README.md file to learn more.
128+
```bash
129+
pnpm run dev
130+
```
95131

96132
#### Note on standalone execution
97133

@@ -103,8 +139,17 @@ You can use Gitpod (An Online Open Source VS Code like IDE which is free for Ope
103139
104140
- clone the `TanStack/form` repo.
105141
- install all the dependencies in `/` and `/docs`.
106-
- run `npm start` in the root(`/`) to Auto-build files.
107-
- run `npm run dev` in `/docs`.
142+
- run below in the root(`/`) to Auto-build files.
143+
144+
```bash
145+
npm start
146+
```
147+
148+
- run below in `/docs`.
149+
150+
```bash
151+
npm run dev
152+
```
108153
109154
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/TanStack/form)
110155
@@ -119,7 +164,7 @@ We have very precise rules over how our git commit messages can be formatted. Th
119164
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
120165
format that includes a **type**, a **scope** and a **subject**:
121166
122-
```
167+
```text
123168
<type>(<scope>): <subject>
124169
<BLANK LINE>
125170
<body>
@@ -138,17 +183,15 @@ Must be one of the following:
138183
- **feat**: A new feature
139184
- **fix**: A bug fix
140185
- **docs**: Documentation only changes
141-
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing
142-
semi-colons, etc)
186+
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
143187
- **refactor**: A code change that neither fixes a bug nor adds a feature
144188
- **perf**: A code change that improves performance
145189
- **test**: Adding missing or correcting existing tests
146-
- **chore**: Changes to the build process or auxiliary tools and libraries such as documentation
147-
generation
190+
- **chore**: Changes to the build process or auxiliary tools and libraries such as documentation generation
148191
149192
### Scope
150193
151-
The scope could be anything specifying place of the commit change. For example `useForm`, `useMutation` etc...
194+
The scope could be anything specifying place of the commit change. For example `form-core`, `react-form` etc...
152195
153196
You can use `*` when the change affects more than a single scope.
154197
@@ -174,11 +217,11 @@ The footer should contain any information about **Breaking Changes** and is also
174217

175218
Here is an example of the release type that will be done based on a commit messages:
176219

177-
| Commit message | Release type |
178-
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
179-
| `fix(pencil): stop graphite breaking when too much pressure applied` | Patch Release |
180-
| `feat(pencil): add 'graphiteWidth' option` | ~~Minor~~ Feature Release |
181-
| `perf(pencil): remove graphiteWidth option`<br><br>`BREAKING CHANGE: The graphiteWidth option has been removed.`<br>`The default graphite width of 10mm is always used for performance reasons.` | ~~Major~~ Breaking Release |
220+
| Commit message | Release type |
221+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
222+
| fix(pencil): stop graphite breaking when too much pressure applied | Patch Release |
223+
| feat(pencil): add `graphiteWidth` option | ~~Minor~~ Feature Release |
224+
| perf(pencil): remove `graphiteWidth` option<br/><br/>BREAKING CHANGE: The `graphiteWidth` option has been removed.<br/>The default graphite width of 10mm is always used for performance reasons. | ~~Major~~ Breaking Release |
182225

183226
### Revert
184227

docs/framework/react/guides/form-composition.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: form-composition
33
title: Form Composition
44
---
55

6-
A common criticism of TanStack Form is its verbosity out-of-the-box. While this _can_ be useful for educational purposes - helping enforce understanding our APIs - it's not ideal in production usecases.
6+
A common criticism of TanStack Form is its verbosity out-of-the-box. While this _can_ be useful for educational purposes - helping enforce understanding our APIs - it's not ideal in production use cases.
77

88
As a result, while `form.Field` enables the most powerful and flexible usage of TanStack Form, we provide APIs that wrap it and make your application code less verbose.
99

@@ -18,7 +18,9 @@ At it's most basic, `createFormHook` is a function that takes a `fieldContext` a
1818
```tsx
1919
import { createFormHookContexts, createFormHook } from '@tanstack/react-form'
2020

21-
const { fieldContext, formContext } = createFormHookContexts()
21+
// export useFieldContext for use in your custom components
22+
export const { fieldContext, formContext, useFieldContext } =
23+
createFormHookContexts()
2224

2325
const { useAppForm } = createFormHook({
2426
fieldContext,
@@ -45,9 +47,12 @@ function App() {
4547

4648
Once this scaffolding is in place, you can start adding custom field and form components to your form hook.
4749

50+
> Note: the `useFieldContext` must be the same one exported from your custom form context
51+
4852
```tsx
49-
function TextField({ label }: { label: string }) {
50-
// Use the context returned from `createFormHookContexts`
53+
import { useFieldContext } from './form-context.tsx'
54+
55+
export function TextField({ label }: { label: string }) {
5156
// The `Field` infers that it should have a `value` type of `string`
5257
const field = useFieldContext<string>()
5358
return (
@@ -65,6 +70,8 @@ function TextField({ label }: { label: string }) {
6570
You're then able to register this component with your form hook.
6671

6772
```tsx
73+
import { TextField } from './text-field.tsx'
74+
6875
const { useAppForm } = createFormHook({
6976
fieldContext,
7077
formContext,

docs/framework/react/guides/reactivity.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ While it IS possible to omit the selector, resist the urge as omitting it would
3131
The `form.Subscribe` component is best suited when you need to react to something within the UI of your component. For example, showing or hiding ui based on the value of a form field.
3232

3333
```tsx
34-
<form.Subscribe>
35-
selector={(state) => state.firstName}
34+
<form.Subscribe
35+
selector={(state) => state.values.firstName}
3636
children={(firstName) => (
37-
<form.Field>{(field) => <input name="lastName" value={field.state.lastName} onChange={field.handleChange}/></form.Field>
37+
<form.Field>
38+
{(field) => (
39+
<input
40+
name="lastName"
41+
value={field.state.lastName}
42+
onChange={field.handleChange}
43+
/>
44+
)}
45+
</form.Field>
3846
)}
39-
</form.Subscribe>
47+
/>
4048
```
4149

4250
> The `form.Subscribe` component doesn't trigger component-level re-renders. Anytime the value subscribed to changes, only the `form.Subscribe` component re-renders.

docs/framework/react/reference/functions/createformhook.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: createFormHook
1111
function createFormHook<TComponents, TFormComponents>(__namedParameters): object
1212
```
1313

14-
Defined in: [packages/react-form/src/createFormHook.tsx:186](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L186)
14+
Defined in: [packages/react-form/src/createFormHook.tsx:223](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L223)
1515

1616
## Type Parameters
1717

@@ -101,7 +101,7 @@ withForm: <TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync
101101

102102
##### \_\_namedParameters
103103

104-
`WithFormProps`\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`, `TSubmitMeta`, `TComponents`, `TFormComponents`, `TRenderProps`\>
104+
[`WithFormProps`](../interfaces/withformprops.md)\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`, `TSubmitMeta`, `TComponents`, `TFormComponents`, `TRenderProps`\>
105105

106106
#### Returns
107107

@@ -111,7 +111,7 @@ withForm: <TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync
111111

112112
###### props
113113

114-
`PropsWithChildren`\<`NoInfer`\<`TRenderProps`\> & `object`\>
114+
`PropsWithChildren`\<`NoInfer`\<`UnwrapOrAny`\<`TRenderProps`\>\> & `object`\>
115115

116116
##### Returns
117117

docs/framework/react/reference/functions/createformhookcontexts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: createFormHookContexts
1111
function createFormHookContexts(): object
1212
```
1313

14-
Defined in: [packages/react-form/src/createFormHook.tsx:16](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L16)
14+
Defined in: [packages/react-form/src/createFormHook.tsx:53](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L53)
1515

1616
## Returns
1717

docs/framework/react/reference/functions/usetransform.md

+4-26
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,21 @@ title: useTransform
88
# Function: useTransform()
99

1010
```ts
11-
function useTransform<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnServer, TSubmitMeta>(fn, deps): FormTransform<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnServer, TSubmitMeta>
11+
function useTransform(fn, deps): FormTransform<any, any, any, any, any, any, any, any, any, any>
1212
```
1313

14-
Defined in: [packages/react-form/src/useTransform.ts:8](https://github.com/TanStack/form/blob/main/packages/react-form/src/useTransform.ts#L8)
15-
16-
## Type Parameters
17-
18-
**TFormData**
19-
20-
**TOnMount** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
21-
22-
**TOnChange** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
23-
24-
**TOnChangeAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
25-
26-
**TOnBlur** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
27-
28-
**TOnBlurAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
29-
30-
**TOnSubmit** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
31-
32-
**TOnSubmitAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
33-
34-
**TOnServer** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
35-
36-
**TSubmitMeta**
14+
Defined in: [packages/react-form/src/useTransform.ts:9](https://github.com/TanStack/form/blob/main/packages/react-form/src/useTransform.ts#L9)
3715

3816
## Parameters
3917

4018
### fn
4119

42-
(`formBase`) => `FormApi`\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`, `TSubmitMeta`\>
20+
(`formBase`) => `AnyFormApi`
4321

4422
### deps
4523

4624
`unknown`[]
4725

4826
## Returns
4927

50-
`FormTransform`\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`, `TSubmitMeta`\>
28+
`FormTransform`\<`any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\>

docs/framework/react/reference/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ title: "@tanstack/react-form"
1010
## Interfaces
1111

1212
- [ReactFormApi](interfaces/reactformapi.md)
13+
- [WithFormProps](interfaces/withformprops.md)
1314

1415
## Type Aliases
1516

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
id: WithFormProps
3+
title: WithFormProps
4+
---
5+
6+
<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7+
8+
# Interface: WithFormProps\<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnServer, TSubmitMeta, TFieldComponents, TFormComponents, TRenderProps\>
9+
10+
Defined in: [packages/react-form/src/createFormHook.tsx:173](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L173)
11+
12+
## Extends
13+
14+
- `FormOptions`\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`, `TSubmitMeta`\>
15+
16+
## Type Parameters
17+
18+
**TFormData**
19+
20+
**TOnMount** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
21+
22+
**TOnChange** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
23+
24+
**TOnChangeAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
25+
26+
**TOnBlur** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
27+
28+
**TOnBlurAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
29+
30+
**TOnSubmit** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\>
31+
32+
**TOnSubmitAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
33+
34+
**TOnServer** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\>
35+
36+
**TSubmitMeta**
37+
38+
**TFieldComponents** *extends* `Record`\<`string`, `ComponentType`\<`any`\>\>
39+
40+
**TFormComponents** *extends* `Record`\<`string`, `ComponentType`\<`any`\>\>
41+
42+
**TRenderProps** *extends* `Record`\<`string`, `unknown`\> = `Record`\<`string`, `never`\>
43+
44+
## Properties
45+
46+
### props?
47+
48+
```ts
49+
optional props: TRenderProps;
50+
```
51+
52+
Defined in: [packages/react-form/src/createFormHook.tsx:200](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L200)
53+
54+
***
55+
56+
### render()
57+
58+
```ts
59+
render: (props) => Element;
60+
```
61+
62+
Defined in: [packages/react-form/src/createFormHook.tsx:201](https://github.com/TanStack/form/blob/main/packages/react-form/src/createFormHook.tsx#L201)
63+
64+
#### Parameters
65+
66+
##### props
67+
68+
`PropsWithChildren`\<`NoInfer`\<`TRenderProps`\> & `object`\>
69+
70+
#### Returns
71+
72+
`Element`

docs/framework/solid/reference/functions/createfield.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: createField
1111
function createField<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta>(opts): () => FieldApi<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta> & SolidFieldApi<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta>
1212
```
1313

14-
Defined in: [packages/solid-form/src/createField.tsx:237](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L237)
14+
Defined in: [packages/solid-form/src/createField.tsx:236](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L236)
1515

1616
## Type Parameters
1717

0 commit comments

Comments
 (0)