Last active
May 1, 2023 01:59
-
-
Save petermoresi/ce9d575b6d6aa64b99e0 to your computer and use it in GitHub Desktop.
A simple ES6 React component to render a list of names
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'; | |
class NameList extends React.Component { | |
constructor(props){ | |
super(props); | |
} | |
render() { | |
var i = 1; | |
var list = this.props.names.map( (name) => { | |
return <div key={i++}>{name}</div>; | |
}); | |
return <div>{list}</div>; | |
} | |
} | |
NameList.propTypes = { | |
names: React.PropTypes.array.isRequired | |
}; | |
React.render( | |
<NameList names={ ['John', 'Fred', 'Larry'] } />, | |
document.querySelector('body') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment