title: state undefined inside async function ( Cannot read property 'filter' of undefined ) - react js
body: <p>My code is straight forward and it looks like I am using list as the local state and have updated it once data are fetched,  the list is perfectly loading on the tbody but still is undefined inside <code>handleDelete</code></p>
  <pre><code>const [list, setList] = useState([]);
  
  useEffect(async () =&gt; {
      fetchData();
  }, []);
  
   async function fetchData() {
      const { data } = await supplier.listSupplier();
      setList(data.data);
  }
  
  const confirmDelete = (id) =&gt; {
      alertify.confirm(() =&gt; {
          handleDelete(id);
      });
  };
  
  const handleDelete = async (id) =&gt; {
      console.log(&quot;list&gt;&gt;&quot;, list); //returning undefined
      const originalList = list;
      const list = list.filter((r) =&gt; r.id !== id); // throwing Cannot read property 'filter' of undefined
      setState(list);
      try {
          await supplier.deleteSupplier(id);
          alertify.success(&quot;Successfully Deleted&quot;);
      } catch (ex) {
          if (ex.response &amp;&amp; ex.response.status === 404) {
              toastify.error(&quot;Already Deleted.&quot;);
          }
          setState(originalList);
      }
  };
  
  return(
      
       &lt;tbody&gt;
          {list &amp;&amp;
              list.map((row, i) =&gt; (
                  &lt;tr key={row.id}&gt;
                      &lt;td&gt;
                              &lt;button
                                  className=&quot;btn btn-danger btn-xs&quot;
                                  title=&quot;Delete&quot;
                                  onClick={() =&gt; confirmDelete(row.id)}
                              &gt;
                                  &lt;i className=&quot;fas fa-trash&quot;&gt;&lt;/i&gt;
                              &lt;/button&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              ))}
      &lt;/tbody&gt;
  
  )
  </code></pre>
  <p>Here, on <code>handleDelete()</code> its throwing error <code>throwing Cannot read property 'filter' of undefined</code> and its obvious that list seems to be undefined down there. How could I fix this?</p>