Skip to content
Open
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
31 changes: 31 additions & 0 deletions src/content/reference/react-dom/components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,38 @@ export default function Search() {
);
}
```
</Sandpack>

### Preventing form reset {/*preventing-form-reset*/}

By default, forms using the `action` prop reset after submission.

If you want to preserve form state, use controlled inputs with React state.

<Sandpack>

```js src/App.js
import { useState } from "react";

export default function Form() {
const [value, setValue] = useState("");

async function handleSubmit(formData) {
// handle submission
}

return (
<form action={handleSubmit}>
<input
name="text"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
<button type="submit">Submit</button>
</form>
);
}
```
</Sandpack>

### Handle form submission with a Server Function {/*handle-form-submission-with-a-server-function*/}
Expand Down
Loading