Last active
October 11, 2019 10:48
-
-
Save davemackintosh/68cca9b35b37b674790f8e0f76af206a to your computer and use it in GitHub Desktop.
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 from "react" | |
export const MyFormWithState = (props) => { | |
const [formState, setFormState] = useState({ | |
name: "", | |
age: 0, | |
}) | |
const onChange = (event) => | |
setFormState({ | |
...formState, | |
[event.currentTarget.name]: event.currentTarget.value, | |
}) | |
return ( | |
<form onSubmit={props.onSubmit}> | |
<fieldset> | |
<label htmlFor="name">Name</label> | |
<input | |
onChange={onChange} | |
name="name" | |
type="text" | |
value={formState.name} | |
/> | |
<label htmlFor="age">Age</label> | |
<input | |
onChange={onChange} | |
name="age" | |
type="number" | |
value={formState.age} | |
/> | |
</fieldset> | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment