Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class MyComponent extends React.Component {
  2.  
  3. componentDidMount() {
  4. this.isMounted = true;
  5. }
  6.  
  7. componentWillUnmount() {
  8. this.isMounted = false;
  9. }
  10.  
  11. render() {
  12. return (
  13. <div>
  14. {this.state.now}
  15. </div>
  16. );
  17. }
  18.  
  19. updateTimeEverySecond() {
  20. setInterval(() => {
  21. if (this.isMounted) {
  22. this.setState({
  23. now: new Date().toISOString(),
  24. });
  25. }
  26. }, 1000);
  27. }
  28. }
Add Comment
Please, Sign In to add comment