ComponentDidMount (componentDidMount) is the first life cycle method, which is a mount. Normally, we want to get the requested interface data when we enter the page, so we can call componentDidMount, but remember that this method is only executed once

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {date: new Date(a)}; }componentDidMount(){}componentWillUnmount(){}render() {
    return (
      <div>
        <h1>Hello, world!</h1>
        <h2>It is {this.state.date.toLocaleTimeString()}.</h2>
      </div>); }}Copy the code

The life cycle function componentWillUnmount is used to remove some operations after the page has been rendered. This method is used to execute what you want to execute when the page is about to be unmounted. This method is usually used to clear some timers of the page or unbind the DOM.