SHARE
TWEET

Untitled

a guest Oct 18th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2.  
  3. class Counter extends React.Component {
  4.   constructor() {
  5.     super()
  6.     this.state = {
  7.       counter: 0
  8.     }
  9.     this.handleIncrement = this.handleIncrement.bind(this)
  10.   }
  11.  
  12.   componentDidMount() {
  13.     document.title = this.state.counter;
  14.   }
  15.  
  16.   componentDidUpdate(prevProps, prevState) {
  17.     if (prevState.counter <= 10) {
  18.     document.title = this.state.counter;
  19.     }
  20.   }
  21.  
  22.   handleIncrement() {
  23.     this.setState({
  24.       counter: this.state.counter += 1
  25.     })
  26.   }
  27.  
  28.   render() {
  29.     return (
  30.       <div>
  31.         <div>{this.state.counter}</div>
  32.         <hr />
  33.         <button type="button" onClick={this.handleIncrement}>+</button>
  34.      </div>
  35.     )
  36.   }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top