Skip to content

Instantly share code, notes, and snippets.

@RyanAtViceSoftware
Last active December 19, 2015 16:41
Show Gist options
  • Save RyanAtViceSoftware/05468e7793d506a4397c to your computer and use it in GitHub Desktop.
Save RyanAtViceSoftware/05468e7793d506a4397c to your computer and use it in GitHub Desktop.
Hello React - dynamic components. JsFiddle: http://jsfiddle.net/gh/gist/library/pure/05468e7793d506a4397c
<script src="https://fb.me/react-with-addons-0.14.0.js"></script>
<script src="https://fb.me/react-dom-0.14.0.js"></script>
<div id="view"/>
var UserRow = React.createClass({
render: function() {
return (
<tr>
<td>{this.props.user.userName}</td>
<td>
<a href={'mailto:' + this.props.user.email}>
{this.props.user.email}
</a>
</td>
</tr>
);
}
});
var UserList = React.createClass({
getInitialState: function() {
return {
users: [
{id: 1, userName: 'RyanVice', email: 'ryan@vicesoftware.com'},
{id: 2, userName: 'AdamHorton', email: 'digitalicarus@gmail.com'}
]
};
},
render: function() {
var users = this.state.users.map(function(user) {
// key prevents react warning
return <UserRow user={user} key={user.id}/>
});
return (
<table>
<tr>
<th>User Name</th>
<th>Email Address</th>
</tr>
{users}
</table>
);
}
});
ReactDOM.render(
<UserList/>,
document.getElementById('view'));
name: ReactJs example by Ryan Vice - www.ViceSoftware.com
description: Hello React - dynamic components.
authors:
- Ryan Vice
resources:
normalize_css: no
wrap: h
panel_js: 3
panel_css: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment