Created
June 22, 2016 18:42
-
-
Save jtribble/4bb4c91a01d86ac8bf88ed1b63935293 to your computer and use it in GitHub Desktop.
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
// | |
// Component with ES2015 features | |
// | |
import React, {PropTypes} from 'react'; | |
const List = React.createClass({ | |
propTypes: { | |
items: PropTypes.array.isRequired, | |
onItemClick: PropTypes.func.isRequired | |
}, | |
handleClick(e, item) { | |
e.preventDefault(); | |
this.props.onItemClick(item); | |
}, | |
render() { | |
const {items} = this.props; | |
return ( | |
<ul> | |
{items.map(item => ( | |
<li> | |
<a onClick={e => this.handleClick(e, item)}> | |
{`Item "${item.text}" for sale`} | |
</a> | |
</li> | |
))} | |
</ul> | |
); | |
} | |
}); | |
export default List; | |
// | |
// Component without ES2015 features | |
// | |
var React = require('react'); | |
var List = React.createClass({ | |
propTypes: { | |
items: React.PropTypes.array.isRequired, | |
onItemClick: React.PropTypes.func.isRequired | |
}, | |
handleClick: function handleClick(item, e) { | |
e.preventDefault(); | |
this.props.onItemClick(item); | |
}, | |
render: function render() { | |
var self = this; | |
return ( | |
<ul> | |
{this.props.items.map(function(item) { | |
return ( | |
<li> | |
<a onClick={self.handleClick.bind(self, item)}> | |
{'Item: "' + item.text + '" for sale'} | |
</a> | |
</li> | |
); | |
})} | |
</ul> | |
); | |
} | |
}); | |
module.exports = List; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment