title: React Hooks - Prevent re-render when using prevState
body: <p>I would like to be able to conditionally set a state based on previous state changes with React Hooks. But if the state remains the same the component shouldn't re-render.</p>
  <p>When using class components, I was able to achieve this using:</p>
  <pre><code>this.setState(prevState =&gt; {
     if(prevState.value !== true) {
       return { value: true }
     }
  
     return null
  })
  </code></pre>
  <p>The code above sets the state to <code>true</code>, only if it's not <code>true</code>. However, if it's already <code>true</code>, <strong>the component doesn't re-render</strong>. I would like to achieve the same effect with React Hooks.</p>
  <p>I know that with React Hooks, I can use the <code>prevState</code> like this:</p>
  <pre><code>setValue(prevValue =&gt; {
     // some code
     return newValue
  })
  </code></pre>
  <p>However, I don't know how to prevent re-render if the state remains the same. Is it possible for me to prevent render after using React Hooks <code>prevState</code>? Thank you for your concern.</p>