Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Created July 5, 2018 01:35
Show Gist options
  • Save MostlyFocusedMike/e57f9f4b54d306da704f4857e85d2b1b to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/e57f9f4b54d306da704f4857e85d2b1b to your computer and use it in GitHub Desktop.
// src/components/CatInputs.js
import React from "react"
const CatInputs = (props) => {
return (
props.cats.map((val, idx)=> {
let catId = `cat-${idx}`, ageId = `age-${idx}`
return (
<div key={idx}>
<label htmlFor={catId}>{`Cat #${idx + 1}`}</label>
<input
type="text"
name={catId}
data-id={idx}
id={catId}
value={props.cats[idx].name}
className="name"
/>
<label htmlFor={ageId}>Age</label>
<input
type="text"
name={ageId}
data-id={idx}
id={ageId}
value={props.cats[idx].age}
className="age"
/>
</div>
)
})
)
}
export default CatInputs
@Mashael-Alotaibi
Copy link

@arvind625 Its a functional component change 'this.props.cats' to 'props.cats'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment