Skip to content

Instantly share code, notes, and snippets.

@tomewer
Created July 6, 2016 15:18
Show Gist options
  • Save tomewer/0547407f9dc1cc10970319a70672455d to your computer and use it in GitHub Desktop.
Save tomewer/0547407f9dc1cc10970319a70672455d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
var ThoreauQuote = React.createClass({
getInitialState: function() {
return {
quoteContent: '',
quoteID: ''
};
},
componentDidMount: function() {
this.serverRequest = $.get(this.props.source, function (result) {
var firstQuote = result[0];
this.setState({
quoteID: firstQuote.id,
quoteTitle: firstQuote.title.rendered,
quoteContent: firstQuote.content.rendered
});
}.bind(this));
},
componentWillUnmount: function() {
this.serverRequest.abort();
},
render: function() {
return (
<div>
<b>Quote ID:</b> {this.state.quoteID}<br/>
<b>Quote Title:</b> {this.state.quoteTitle}<br/>
<b>Quote Content:</b> {this.state.quoteContent}<br/>
</div>
);
}
});
ReactDOM.render(
<ThoreauQuote source="http://walden.dev/wp-json/wp/v2/posts" />,
document.getElementById('example')
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment