Skip to content

Instantly share code, notes, and snippets.

@gunar
Created April 3, 2019 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunar/a04a0b0516c52f17923e370a7fb2d5bc to your computer and use it in GitHub Desktop.
Save gunar/a04a0b0516c52f17923e370a7fb2d5bc to your computer and use it in GitHub Desktop.
How to Reset Forms in React.
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