Guest User

Untitled

a guest
Sep 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. //src/MyTimer.js
  2.  
  3.  
  4. import React, { Component } from "react";
  5.  
  6.  
  7.  
  8.  
  9. class Clock extends React.Component {
  10.  
  11. constructor(props) {
  12. super(props);
  13. this.state = {time: 0};
  14. }
  15.  
  16.  
  17. componentDidMount() {
  18. this.counter = setInterval(
  19. () => this.second(),
  20. 1000
  21. );
  22. }
  23.  
  24.  
  25. componentWillUnmount() {
  26. clearInterval(this.counter);
  27. }
  28.  
  29.  
  30. second() {
  31. this.setState(
  32. state => time: state.time + 1
  33. );
  34. console.log('un update a eu lieu')
  35. }
  36.  
  37.  
  38. render() {
  39. return (
  40. <div>
  41. <h1>{this.state.time}</h1>
  42. </div>
  43. );
  44. }
  45. }
  46.  
  47.  
  48. ReactDom.render(
  49. <Clock />
  50. document.getElementByTd("root")
  51. );
Add Comment
Please, Sign In to add comment