title: What is the advantage of passing function to setState() in React?
body: <p>I have a function called <code>onRemove</code> that is written like this: </p>
  
  <pre><code>const [todos, setTodos] = useState(todoData);
  
  const onRemove = useCallback(
      (id) =&gt; {
        setTodos(todos.filter((todo) =&gt; todo.id !== id));
      },
      [todos]
    );
  </code></pre>
  
  <p>Then I noticed that changing it functional resulted in shorter rendering time.</p>
  
  <pre><code>const onRemove = useCallback(
      (id) =&gt; {
        setTodos(todos =&gt; todos.filter((todo) =&gt; todo.id !== id));
      },
      []
    );
  </code></pre>
  
  <p>My question is: </p>
  
  <ol>
  <li>Why does it render components quicker?</li>
  <li>What are the other advantages of using functional <code>setState()</code>?</li>
  </ol>