mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
This covers most everything. The perf suite still needs work for the Element updates. And the server rendering example needs to be done wholesale.
29 lines
709 B
JavaScript
29 lines
709 B
JavaScript
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 (\n\
|
|
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>\n\
|
|
);\n\
|
|
}\n\
|
|
});\n\
|
|
\n\
|
|
React.render(<Timer />, mountNode);\
|
|
";
|
|
|
|
React.render(
|
|
<ReactPlayground codeText={TIMER_COMPONENT} />,
|
|
document.getElementById('timerExample')
|
|
);
|