Skip to content

Instantly share code, notes, and snippets.

@dineshPallapa
Last active July 25, 2017 08:50
Show Gist options
  • Save dineshPallapa/45a3c474081c9df1990729efe16c4ae8 to your computer and use it in GitHub Desktop.
Save dineshPallapa/45a3c474081c9df1990729efe16c4ae8 to your computer and use it in GitHub Desktop.
class Profile extends React.Component{
render() {
let hobbies = this.props.hobbies.map(hobbie => {
return(
<li>{hobbie}</li>
)
})
return(
<div>
<h3>{this.props.name}</h3>
<h3>{this.props.age}</h3>
<ul>{hobbies}</ul>
</div>
)
}
}
class App extends React.Component{
constructor(props) {
super(props)
this.state = {
name:"Dinesh",
profiles: [
{name:"dinesh",age :23,hobbies:["Playing cards","Mobile games"]},
{name:"Virus",age:24,hobbies:["eating","sleeping"]}
]
}
}
render() {
let profiles = this.state.profiles.map(profile => {
return(
<Profile name={profile.name}
age={profile.age}
hobbies={profile.hobbies}
/>
)
})
return (
<div>
{profiles}
<Profile name={"dinesh"} age={20} hobbies={["eating","drinking"]} />
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment