Skip to content

Add useFormState permalink arg #6402

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

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/content/reference/react-dom/hooks/useFormState.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The `useFormState` Hook is currently only available in React's canary and experi
`useFormState` is a Hook that allows you to update state based on the result of a form action.

```js
const [state, formAction] = useFormState(fn, initialState);
const [state, formAction] = useFormState(fn, initialState, permalink?);
```

</Intro>
Expand All @@ -25,7 +25,7 @@ const [state, formAction] = useFormState(fn, initialState);

## Reference {/*reference*/}

### `useFormState(action, initialState)` {/*useformstate*/}
### `useFormState(action, initialState, permalink?)` {/*useformstate*/}

{/* TODO T164397693: link to actions documentation once it exists */}

Expand Down Expand Up @@ -59,6 +59,7 @@ If used with a server action, `useFormState` allows the server's response from s

* `fn`: The function to be called when the form is submitted or button pressed. When the function is called, it will receive the previous state of the form (initially the `initialState` that you pass, subsequently its previous return value) as its initial argument, followed by the arguments that a form action normally receives.
* `initialState`: The value you want the state to be initially. It can be any serializable value. This argument is ignored after the action is first invoked.
* **optional** `permalink`: A string containing the unique page URL that this form modifies. For use on pages with dynamic content (eg: feeds) in conjunction with progressive enhancement: if `fn` is a [server action](/reference/react/use-server) and the form is submitted before the JavaScript bundle loads, the browser will navigate to the specified permalink URL, rather than the current page's URL. Ensure that the same form component is rendered on the destination page (including the same action `fn` and `permalink`) so that React knows how to pass the state through. Once the form has been hydrated, this parameter has no effect.

{/* TODO T164397693: link to serializable values docs once it exists */}

Expand Down