Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. var Timer = React.createClass({
  2. getInitialState: function() {
  3. return {secondsElapsed: 0};
  4. },
  5. tick: function() {
  6. this.setState({secondsElapsed: this.state.secondsElapsed + 1});
  7. },
  8. componentDidMount: function() {
  9. this.interval = setInterval(this.tick, 1000);
  10. },
  11. componentWillUnmount: function() {
  12. clearInterval(this.interval);
  13. },
  14. render: function() {
  15. return (
  16. <div>Seconds Elapsed: {this.state.secondsElapsed}</div>
  17. );
  18. }
  19. });
  20.  
  21. React.renderComponent(<Timer />, mountNode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement