Unform
Reset form
Reset form
There are two ways to reset all form data:
Reset after submit
Besides the data
, the onSubmit
function also receives a second parameter with form helpers like resetForm
:
export default function SignIn() { function handleSubmit(data, { reset }) { console.log(data); reset(); } return <Form onSubmit={handleSubmit}>...</Form>;}
Reset form manually
If you need to reset form data without a submit use the reset
function exposed inside form reference.
export default function SignIn() { const formRef = useRef(null); function functionThatResetsForm() { formRef.current.reset(); // You can also clear a single input value formRef.current.clearField('email'); } return ( <Form ref={formRef} onSubmit={handleSubmit}> <Input name="email" /> </Form> );}