JSFiddle - React, Tailwind, and code Playground
by daver182
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<div id="root"></div>
JavaScript
var Clock = React.createClass({
getInitialState: function() {
return {time: new Date()};
},
componentDidMount: function() {
window.setInterval(this.tick, 1000);
},
tick: function() {
this.setState({ time: new Date() });
},
render: function() {
return React.createElement(
'div',
null,
this.props.title + ': ' +
this.state.time.getHours() + ':' +
this.state.time.getMinutes() + ':' +
this.state.time.getSeconds()
);
}
});
ReactDOM.render(
React.createElement(Clock, {title: 'Time'}, null),
document.getElementById('root')
);