Last active
February 15, 2016 10:38
-
-
Save vnglst/519f151454a037d1184b to your computer and use it in GitHub Desktop.
React examples
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
// React stateless components examples | |
// Example based on egghead.io lesson 14 | |
// https://egghead.io/lessons/react-building-stateless-function-components-new-in-react-0-14 | |
// Stateless component definition as function | |
const UserList = ({users}) => ( | |
<div> | |
{users.map(user => { | |
return <div>{user.name} - {user.type)</div> | |
})} | |
</div> | |
); | |
// Adding prop types | |
import React, { PropTypes } from 'react'; | |
UserList.propTypes = { | |
users: React.PropTypes.arrayOf(React.PropTypes.object).isRequired | |
}; | |
// Exporting as module | |
export default UserList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment