Last active
December 19, 2015 16:41
-
-
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
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
<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"/> |
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
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')); |
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
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