Skip to content

Instantly share code, notes, and snippets.

@trepidity
Created December 28, 2016 22:24
Show Gist options
  • Select an option

  • Save trepidity/a9103dce131f9cf0f55e1fe161ebbb2e to your computer and use it in GitHub Desktop.

Select an option

Save trepidity/a9103dce131f9cf0f55e1fe161ebbb2e to your computer and use it in GitHub Desktop.
Parsing a json object in React
const dataW = [
{
"id": "1",
"type": "messages",
"attributes": {
"body": "Example Message 1",
"updated-at": "2016-12-28T18:32:50.176Z"
}
}
]
class Message extends React.Component {
render() {
return (<div>
<h5>{this.props.message.attributes['updated-at']}</h5>
<p>{this.props.message.attributes.body}</p>
</div>
);
}
}
export default React.createClass({
render() {
return ( <div><h3>Messages</h3><MessageList messages={dataW} /></div>);
}
})
class MessageList extends React.Component {
render() {
var rows = [];
this.props.messages.forEach(function(message) {
rows.push(<Message message={message} key={message.id} />);
});
return (
<div>{rows}</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment