componentDidUpdate vs componentWillReceiveProps use case in react : <p>This is how we use <code>componentWillReceiveProps</code></p>

<pre><code>componentWillReceiveProps(nextProps) {
  if(nextProps.myProp !== this.props.myProps) {
    // nextProps.myProp has a different value than our current prop
  }
}
</code></pre>

<p>It's very similar to <code>componentDidUpdate</code></p>

<pre><code>componentDidUpdate(prevProps) {
  if(prevProps.myProps !== this.props.myProp) {
    // this.props.myProp has a different value
    // ...
  }
}
</code></pre>

<p>I can see some differences, like if I do setState in componentDidUpdate, render will trigger twice, and the argument for componentWillReceiveProps is nextProps, while argument for <code>componentDidUpdate</code> is prevProp, but seriously I don't know when to use them. I often use <code>componentDidUpdate</code>, but with prevState, like change a dropdown state and call api</p>

<p>eg.</p>

<pre><code>componentDidUpdate(prevProps, prevState) {
      if(prevState.seleted !== this.state.seleted) {
        this.setState({ selected: something}, ()=&gt; callAPI())
      }
    }
</code></pre>
