react/docs/_js/examples/timer.js
Ben Alpert e379f8ec03 Fix all errors and warnings on homepage
Also onChange instead of onInput in two places!
2013-07-17 13:31:52 -07:00

33 lines
762 B
JavaScript

/**
* @jsx React.DOM
*/
var TIMER_COMPONENT = "\
var Timer = React.createClass({\n\
getInitialState: function() {\n\
return {secondsElapsed: 0};\n\
},\n\
tick: function() {\n\
this.setState({secondsElapsed: this.state.secondsElapsed + 1});\n\
},\n\
componentDidMount: function() {\n\
this.interval = setInterval(this.tick, 1000);\n\
},\n\
componentWillUnmount: function() {\n\
clearInterval(this.interval);\n\
},\n\
render: function() {\n\
return React.DOM.div({},\n\
'Seconds Elapsed: ' + this.state.secondsElapsed\n\
);\n\
}\n\
});\n\
\n\
React.renderComponent(Timer({}), mountNode);\
";
React.renderComponent(
<ReactPlayground codeText={TIMER_COMPONENT} />,
document.getElementById('timerExample')
);