title: ReactJS - error on maximum update depth exceeded despite conditional check
body: <p>After I included the code below in my componentDidUpdate() method I started to get "Error: Maximum update depth exceeded.". My goal is to filter the array 'appointmentsByMonth' every time the selectedDate gets updated and set the state with the resulted value. What am I doing wrong? I appreciate any help. Thanks in advance.</p>
  
  <pre><code>    componentDidUpdate = (prevState) =&gt; {
        const { selectedDate } = this.state;
        const { appointmentsByMonth } = this.props;
  
        if (selectedDate !== prevState.selectedDate) {
          this.setState({visibleAppointments: appointmentsByMonth.filter(apt =&gt; moment(apt.date).format('YYYY-MM-DD') === moment(selectedDate).format('YYYY-MM-DD'))})
      }
  }
  </code></pre>