-
-
Notifications
You must be signed in to change notification settings - Fork 603
docs(react): add reference page for useTransform #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mixelburg
wants to merge
1
commit into
TanStack:main
Choose a base branch
from
mixelburg:docs/usetransform-reference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| id: useTransform | ||
| title: useTransform | ||
| --- | ||
|
|
||
| # Function: useTransform() | ||
|
|
||
| ```ts | ||
| function useTransform( | ||
| fn: (formBase: AnyFormApi) => AnyFormApi, | ||
| deps?: unknown[], | ||
| ): (data: unknown) => unknown; | ||
| ``` | ||
|
|
||
| A hook used in SSR meta-framework adapters (TanStack Start, Next.js, Remix) to merge server-returned form state with the client-side form instance. | ||
|
|
||
| Pass the result directly to the `transform` option of `useForm`. Under the hood it is a stable `useCallback` wrapper, so it only recreates the transform function when `deps` change. | ||
|
|
||
| ## Parameters | ||
|
|
||
| ### fn | ||
|
|
||
| `(formBase: AnyFormApi) => AnyFormApi` | ||
|
|
||
| A function that receives the base form API and returns a transformed form API. Typically calls `mergeForm(baseForm, serverState)` to layer server validation errors or default values on top of the client form. | ||
|
|
||
| ### deps? | ||
|
|
||
| `unknown[]` | ||
|
|
||
| Dependency array for the callback, identical to `useCallback`'s second argument. Include any reactive values referenced inside `fn`. | ||
|
|
||
| ## Returns | ||
|
|
||
| `(data: unknown) => unknown` | ||
|
|
||
| A stable transform function suitable for the `transform` option of `useForm`. | ||
|
|
||
| ## Example | ||
|
|
||
| ```ts | ||
| import { mergeForm, useForm, useTransform } from '@tanstack/react-form-start' | ||
|
|
||
| // serverState comes from a loader / action / server function | ||
| const form = useForm({ | ||
| ...formOpts, | ||
| transform: useTransform( | ||
| (baseForm) => mergeForm(baseForm, serverState), | ||
| [serverState], | ||
| ), | ||
| }) | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - This hook is exported from the meta-framework adapter packages (`@tanstack/react-form-start`, `@tanstack/react-form-nextjs`, `@tanstack/react-form-remix`), not from `@tanstack/react-form` itself. | ||
| - For a full SSR integration example see the [React Meta-Framework Usage guide](../guides/ssr.md). | ||
|
|
||
| ## Defined in | ||
|
|
||
| [packages/react-form-nextjs/src/useTransform.ts](https://github.com/TanStack/form/blob/main/packages/react-form-nextjs/src/useTransform.ts) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/form
Length of output: 387
Clarify the import source for
mergeFormin the documentation.The description references
mergeForm(baseForm, serverState)but does not specify where to import it from.mergeFormis exported from@tanstack/form-core, not from the adapter packages. Update the documentation to clearly indicate the correct import source to prevent user confusion.🤖 Prompt for AI Agents