title: Why do I need prevProps with prevState in componentDidUpdate()?
body: <p>I have built a simple counter app:</p>
  <pre><code>class Counter extends React.Component {
  
    constructor(props) {
      super(props);
      this.handleAddOne = this.handleAddOne.bind(this);
      this.handleMinusOne = this.handleMinusOne.bind(this);
      this.handleReset = this.handleReset.bind(this);
      this.state = {
        count: 0
      };
    }
  
    componentDidMount() {
        const stringCount = localStorage.getItem('count');
        const count = parseInt(stringCount);
  
        if (isNaN(count) === false) {
          this.setState(() =&gt; ({ count }));
        } 
    }
  
    componentDidUpdate(prevProps, prevState) {
      if (prevState.count !== this.state.count) {
        localStorage.setItem('count', this.state.count);
        console.log('componentDidUpdate');
      }
    }
  
    handleAddOne() {
      this.setState((prevState) =&gt; {
        return {
          count: prevState.count + 1
        }
      });
    }
    
    handleMinusOne() {
      console.log('handleMinusOne');
      this.setState((prevState) =&gt; {
        return {
          count: prevState.count - 1
        }
      });
    }
    
    handleReset() {
      this.setState(() =&gt; {
        return {
          count: 0
        }
      });
    }
  
    render() {
      return (
        &lt;div&gt;
          &lt;h1&gt;Count: {this.state.count}&lt;/h1&gt;
          &lt;button onClick={this.handleAddOne}&gt;+&lt;/button&gt;
          &lt;button onClick={this.handleMinusOne}&gt;-1&lt;/button&gt;
          &lt;button onClick={this.handleReset}&gt;reset&lt;/button&gt;
        &lt;/div&gt;
      );
    }
  }
  
  ReactDOM.render(&lt;Counter /&gt;, document.getElementById('app'));
  </code></pre>
  <p>The question I have is with <code>componentDidUpdate()</code>. In it, I am checking to see if the <code>prevState.count</code> is not the same as the <code>this.state.count</code>. If it is not the same, then I set <code>localStorage</code> to the new count. If it is same, I do nothing.</p>
  <p>In the current componentDidUpdate(), I need <code>prevProps</code> as an argument for this function to work correctly. For example, if I just have this:</p>
  <pre><code>componentDidUpdate(prevState) {
      if (prevState.count !== this.state.count) {
        localStorage.setItem('count', this.state.count);
        console.log('componentDidUpdate');
      }
    }
  </code></pre>
  <p>Then the component sets <code>localStorage</code> every time the reset button is pressed repeatedly, even though the count remains at 0.</p>
  <p>What is going on? Why do I need <code>prevProps</code> for <code>componentDidUpdate()</code> to work correctly, if I am never using <code>props</code> in that function?</p>