Created
December 28, 2016 22:24
-
-
Save trepidity/a9103dce131f9cf0f55e1fe161ebbb2e to your computer and use it in GitHub Desktop.
Parsing a json object in React
This file contains hidden or 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
| 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