This repository was archived by the owner on Apr 6, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,21 +3,23 @@ title: Reset form
33description : Manually reseting a form using the resetForm method
44---
55
6+ > Don't use the ` <input type="reset" /> ` to reset the form data. It won't work correctly with Unform and may cause bugs.
7+
68There are two ways to reset all form data:
79
810## 1. Reset after submit
911
10- Besides the ` data ` , the ` onSubmit ` function also receives a second parameter with form helpers like ` resetForm ` :
12+ Besides the ` data ` , the ` onSubmit ` function also receives a second parameter with form helpers:
1113
1214``` jsx
1315export default function SignIn () {
1416 function handleSubmit (data , { reset }) {
15- console .log (data);
17+ console .log (data)
1618
17- reset ();
19+ reset ()
1820 }
1921
20- return < Form onSubmit= {handleSubmit}> ... < / Form> ;
22+ return < Form onSubmit= {handleSubmit}> ... < / Form>
2123}
2224```
2325
@@ -27,19 +29,19 @@ If you need to reset form data without a submit use the `reset` function exposed
2729
2830``` jsx
2931export default function SignIn () {
30- const formRef = useRef (null );
32+ const formRef = useRef (null )
3133
3234 function functionThatResetsForm () {
33- formRef .current .reset ();
35+ formRef .current .reset ()
3436
3537 // You can also clear a single input value
36- formRef .current .clearField (' email' );
38+ formRef .current .clearField (' email' )
3739 }
3840
3941 return (
4042 < Form ref= {formRef} onSubmit= {handleSubmit}>
4143 < Input name= " email" / >
4244 < / Form>
43- );
45+ )
4446}
4547```
You can’t perform that action at this time.
0 commit comments