Answers for "componentWillUnmount"

0

componentWillUnmount

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {date: new Date()};
  }

  componentDidMount() {
    this.timerID = setInterval(
      () => this.tick(),
      1000
    );
  }

  componentWillUnmount() {
    clearInterval(this.timerID);
  }

  tick() {    this.setState({      date: new Date()    });  }
  render() {
    return (
      <div>
        <h1>Bonjour, monde !</h1>
        <h2>Il est {this.state.date.toLocaleTimeString()}.</h2>
      </div>
    );
  }
}

ReactDOM.render(
  <Clock />,
  document.getElementById('root')
);
Posted by: Guest on September-02-2021
0

shouldcomponentupdate

shouldComponentUpdate(nextProps, nextState) {
  return true;
}
Posted by: Guest on June-08-2020
2

component did mmount

componentDidMount()
Posted by: Guest on May-01-2020
2

component did mmount

componentDidUpdate(prevProps, prevState, snapshot)
Posted by: Guest on May-01-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language