title: What is the use case of useMemo in React?
body: <p>I need help to understand when to use <code>useMemo</code> hook in React vs <code>useState</code> + <code>useEffect</code>. From what I've understood after reading other questions on S.O. and websites :</p>
  
  <ul>
  <li>With <code>useState</code> you can create a value (changeable through the <strong><em>setter</em></strong>) and you can use <code>useEffect</code> to do whatever you need if some of the dependencies listed in the <strong>dependency array</strong> changes. On first render for example your component will be rendered with the initial value passed to <code>useState</code>, then the effect will run and your component will re-render with the new value you set with the <strong>setter</strong> in your <strong>effect</strong>.</li>
  <li>With <code>useMemo</code> you can create a value that will be computed from a function you give to the hook and it will change if some of the dependencies in the <strong>dependency array</strong> changes. So far, to me, it looks like <code>useState</code> + <code>useEffect</code> except you don't have the <strong>setter</strong> to change the value. On render your useMemo will run if one of the dependencies has changed. Difference here : your component will wait for the value to be computed before rendering (not sure about this part).</li>
  </ul>
  
  <p>From what I've read, <code>useMemo</code> should be used for heavy operations. But if it's blocks the rendering of the component what's the point ?<br>
  Some says that with the dependency array you can avoid unnecessary updates but I can also do it with useEffect without blocking the render ? If I don't have a heavy component to render, isn't it faster to use useEffect ?</p>
  
  <p>Thank you :) </p>
  
  <p><strong>Edit :</strong><br>
  I accepted Philip Feldmann's answer as it fits my needs. As suggested in the comments you can take a look at <a href="https://stackoverflow.com/questions/54963248/whats-the-difference-between-usecallback-and-usememo-in-practice">this question</a> for a global comparison :)</p>