Created
April 3, 2019 18:12
-
-
Save gunar/a04a0b0516c52f17923e370a7fb2d5bc to your computer and use it in GitHub Desktop.
How to Reset Forms in React.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react' | |
const Form = () => { | |
const [key, setKey] = useState(0) | |
return ( | |
<div key={key}> | |
<input type='text' /> | |
<button onClick={/* ... */}>Submit</button> | |
<button onClick={() => { setKey(key + 1) }}>Reset</button> | |
</div> | |
) | |
} | |
export { | |
Form, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment