Skip to content

Instantly share code, notes, and snippets.

@foxish
Created March 27, 2017 01:35
Show Gist options
  • Save foxish/7b6eb59ff17e4a30625589bc6742f5b1 to your computer and use it in GitHub Desktop.
Save foxish/7b6eb59ff17e4a30625589bc6742f5b1 to your computer and use it in GitHub Desktop.
React JS Example // source http://jsbin.com/papasaq
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-0.13.0.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>React JS Example</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-git.js"></script>
<script id="jsbin-javascript">
var data =
[{ "when": "2 minutes ago",
"who": "Jill Dupre",
"description": "Created new account"
},
{
"when": "1 hour ago",
"who": "Lose White",
"description": "Added first chapter"
},
{
"when": "2 hours ago",
"who": "Jordan Whash",
"description": "Created new account"
}];
var title = "Changes Table"
var headings = ['When', 'Who', 'Description'];
var App = React.createClass({displayName: 'App',
render: function(){
var headings = this.props.headings.map(function(heading) {
return(React.createElement("th", null,
heading
));
});
var rows = this.props.data.map(function(change) {
return(React.createElement("tr", null,
React.createElement("td", null, " ", change.when, " "),
React.createElement("td", null, " ", change.who, " "),
React.createElement("td", null, " ", change.description, " ")
));
});
return React.createElement("div", null,
React.createElement("h1", null,
this.props.title
),
React.createElement("table", null,
headings,
rows
)
)
}
});
React.render(React.createElement(App, {headings: headings,
data: data, title: title}), document.body);
</script>
<script id="jsbin-source-javascript" type="text/javascript">var data =
[{ "when": "2 minutes ago",
"who": "Jill Dupre",
"description": "Created new account"
},
{
"when": "1 hour ago",
"who": "Lose White",
"description": "Added first chapter"
},
{
"when": "2 hours ago",
"who": "Jordan Whash",
"description": "Created new account"
}];
var title = "Changes Table"
var headings = ['When', 'Who', 'Description'];
var App = React.createClass({
render: function(){
var headings = this.props.headings.map(function(heading) {
return(<th>
{heading}
</th>);
});
var rows = this.props.data.map(function(change) {
return(<tr>
<td> { change.when } </td>
<td> { change.who } </td>
<td> { change.description } </td>
</tr>);
});
return <div>
<h1>
{this.props.title}
</h1>
<table>
{headings}
{rows}
</table>
</div>
}
});
React.render(<App headings = {headings}
data = {data} title = {title} />, document.body);</script></body>
</html>
var data =
[{ "when": "2 minutes ago",
"who": "Jill Dupre",
"description": "Created new account"
},
{
"when": "1 hour ago",
"who": "Lose White",
"description": "Added first chapter"
},
{
"when": "2 hours ago",
"who": "Jordan Whash",
"description": "Created new account"
}];
var title = "Changes Table"
var headings = ['When', 'Who', 'Description'];
var App = React.createClass({displayName: 'App',
render: function(){
var headings = this.props.headings.map(function(heading) {
return(React.createElement("th", null,
heading
));
});
var rows = this.props.data.map(function(change) {
return(React.createElement("tr", null,
React.createElement("td", null, " ", change.when, " "),
React.createElement("td", null, " ", change.who, " "),
React.createElement("td", null, " ", change.description, " ")
));
});
return React.createElement("div", null,
React.createElement("h1", null,
this.props.title
),
React.createElement("table", null,
headings,
rows
)
)
}
});
React.render(React.createElement(App, {headings: headings,
data: data, title: title}), document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment