title: React - To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function
body: <p>I have the following code</p>
  <pre><code>const Companies = () =&gt; {
    const [company, setCompany] = useState(plainCompanyObj);
    const [companiesData, setCompaniesData] = useState([]);
    
    useEffect(() =&gt; {
      Call&lt;any, any&gt;({
        url:
          _baseApiUrl +
          &quot;-------api goes here --------&quot;,
        method: &quot;GET&quot;,
        data: null,
        success: (companies) =&gt; {
          setCompaniesData(companies.companies);
        },
        authorization: sessionStorage.getItem(&quot;accessToken&quot;),
      });
    }, []);
  
    return (
      //return JSX
    );
  };
  </code></pre>
  <p>I get the following error: <code>Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.</code></p>
  <p>Also just to clarify the <code>Call</code> tag is a method imported by <code>axios</code> that I use for URL error handler etc. The problem as the error suggests is in the <code>useEffect</code> section.</p>