Created
July 16, 2021 13:57
-
-
Save jagsbyteinception/c23ed86a1fa11113349e1181c7e6631a 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
//common state for different inputs | |
function RegisterYourCatForm() { | |
const [values, setValues] = useState({ | |
name: '', color: '', age: '', habits: '' | |
}); | |
const set = name => { | |
return ({ target: { value } }) => { | |
setValues(oldValues => ({...oldValues, [name]: value })); | |
} | |
}; | |
return ( | |
<form> | |
<h2>Register Your Cat</h2> | |
<label>Name*:</label> | |
<input value={values.name} onChange={set('name')} /> | |
<label>Color*:</label> | |
<select value={values.color} onChange={set('color')}> | |
<option value="">Select color</option> | |
{COLORS.map(c => <option key={c}>{c}</option>)} | |
</select> | |
<label>Age*:</label> | |
<input value={values.age} onChange={set('age')} /> | |
<label>Habits:</label> | |
<textarea value={values.habits} onChange={set('habits')} /> | |
<button type="submit">Submit</button> | |
</form> | |
); | |
} |
Author
jagsbyteinception
commented
Aug 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment