title: componentWillUpdate is deprecated in React, how can I replace it?
body: <p>React 16.3.0 was released and there were changes in React lifecycles. </p>
  
  <p>React does not recommend to use <code>componentWillMount</code>, <code>componentWillReceiveProps</code>, <code>componentWillUpdate</code>.</p>
  
  <p>In that case, what should I use instead of <code>componentWillUpdate</code>?
  For example, in the following code how can I replace <code>componentWillUpdate</code>?</p>
  
  <pre><code>import React from "react";
  import Modal from "./Modal";
  
  class ModalContainer extends React.Component {
    state = {
      openModal: false
    };
    onClick = () =&gt; {
      this.setState({
        openModal: !this.state.openModal
      });
    };
  
    escapeKey = e =&gt; {
      if (e.key === "Escape" &amp;&amp; this.state.openModal === true) {
        this.setState({
          openModal: !this.state.openModal
        });
      }
    };
    componentDidMount() {
      document.body.classList.add("no-scroll");
      this.componentWillUpdate(this.state, this.state);
    }
    componentWillUpdate(p, c) {
      if (c.openModal) {
        window.addEventListener("keyup", this.escapeKey);
      } else {
        window.removeEventListener("keyup", this.escapeKey);
      }
    }
    componentWillUnmount() {
      window.removeEventListener("keyup", this.escapeKey);
    }
  
    render(props) {
      return (
        &lt;div className="ModalContainer"&gt;
          &lt;a className={`ModalContainer-trigger`} onClick={this.onClick}&gt;
            click here to open the modal
          &lt;/a&gt;
          {this.state.openModal &amp;&amp; (
            &lt;Modal
              onClick={this.onClick}
              in={!!this.state.openModal}
              {...this.props}
            /&gt;
          )}{" "}
        &lt;/div&gt;
      );
    }
  }
  export default ModalContainer;
  </code></pre>
  
  <p>Thank you</p>