Last active
July 31, 2019 03:36
-
-
Save MostlyFocusedMike/ad5b9a1a4203b8df631b7136e6651f23 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, { useState } from 'react'; | |
const Form = () => { | |
const [catState, setCatState] = useState([ | |
{ name: '', age: '' }, | |
]); | |
return ( | |
<form> | |
<label htmlFor="owner">Owner</label> | |
<input type="text" name="owner" id="owner" /> | |
<label htmlFor="description">Description</label> | |
<input | |
type="text" | |
name="description" | |
id="description" | |
/> | |
<input type="button" value="Add New Cat" /> | |
{ | |
catState.map((val, idx) => { | |
const catId = `name-${idx}`; | |
const ageId = `age-${idx}`; | |
return ( | |
<div key={`cat-${idx}`}> | |
<label htmlFor={catId}>{`Cat #${idx + 1}`}</label> | |
<input | |
type="text" | |
name={catId} | |
data-idx={idx} | |
id={catId} | |
className="name" | |
/> | |
<label htmlFor={ageId}>Age</label> | |
<input | |
type="text" | |
name={ageId} | |
data-idx={idx} | |
id={ageId} | |
className="age" | |
/> | |
</div> | |
); | |
}) | |
} | |
<input type="submit" value="Submit" /> | |
</form> | |
); | |
}; | |
export default Form; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment