Skip to content

Instantly share code, notes, and snippets.

@petermoresi
Last active May 1, 2023 01:59
Show Gist options
  • Save petermoresi/ce9d575b6d6aa64b99e0 to your computer and use it in GitHub Desktop.
Save petermoresi/ce9d575b6d6aa64b99e0 to your computer and use it in GitHub Desktop.
A simple ES6 React component to render a list of names
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