Skip to content
Open
Changes from 1 commit
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
Next Next commit
docs: explain preventing form reset
  • Loading branch information
nikhilkumar5177 committed Apr 12, 2026
commit 068c6a38eacd6e9478a2c0c2d5997d4d0dcb76df
29 changes: 29 additions & 0 deletions src/content/reference/react-dom/components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ export default function Search() {
);
}
```
### 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>

Expand Down
Loading