mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
29 lines
712 B
JavaScript
29 lines
712 B
JavaScript
var TIMER_COMPONENT = ("\nvar 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 (\n <div>Seconds Elapsed: {this.state.secondsElapsed}</div>\n );\n }\n});\n\nReact.render(<Timer />, mountNode);\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
React.render(
|
|
React.createElement(ReactPlayground, {codeText: TIMER_COMPONENT}),
|
|
document.getElementById('timerExample')
|
|
);
|