title: Set an empty array in state
body: <p>In my application I have a initial state that start with some values.
  In a process, I need to change this state for a empty array, (that is a return of my Api).</p>
  
  <p>I am trying do this, but the value of the state don't change.</p>
  
  <p>What can I do?</p>
  
  <p>My code</p>
  
  <pre><code>import React, {useEffect, useState} from "react";
  import "./style.scss";
  import Services from "../../services/Services";
  
  export default function Acoplamento({history, match}) {
  
      const [veiculos, setVeiculos] = useState([]);
      const [loading, setLoading] = useState(false);
      const [type, setType] = useState(1);
  
      const getAllVeiculos = async () =&gt; {
          setLoading(true);
          await Services.VeiculoServices.getAll().then(result =&gt; {
              setVeiculos(result.data); // Here, i have a array with some objects
          }).catch(error =&gt; {
              error(error.message);
          }).finally(() =&gt; setLoading(false));
          return true;
      }
  
      const getOneVeiculos = async () =&gt; {
          setLoading(true);
          await Services.VeiculoServices.get().then(result =&gt; {
              setVeiculos(result.data); // Here, my return is a empty array, but my state don't chage
          }).catch(error =&gt; {
              error(error.message);
          }).finally(() =&gt; setLoading(false));
          return true;
      }
  
      useEffect(() =&gt; {
          if (type === 1) {
              getAllVeiculos();
          }
          if (type === 2) {
              getOneVeiculos();
          }
      }, [type]);
  
      return (
          &lt;div&gt;
              &lt;button onClick={() =&gt; setType(2)}&gt;Click&lt;/button&gt;
              {veiculos.map(item =&gt; (
                  &lt;div&gt;{item.name}&lt;/div&gt;
              ))}
          &lt;/div&gt;
      );
  }
  
  </code></pre>