title: Problem with react state update on an unmounted component
body: <p>well, when I want to update an item I call UseEffect and make an asynchronous call to my endpoint, but I want to solve the problem when the id doesn't exist in the db, it throws me the following error:  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.</p>
  <pre><code>export const AddOrUpdateItem = () =&gt; {
   
    const {id} = useParams();
    const [itemToUpdate, setItemToUpdate] = useState(null);
    const history = useHistory();
    
    useEffect(() =&gt; {
      if(id) {
        const fetchData = async() =&gt; {
          try {
            const resp = await axios.get(`${ITEMS_ENDPOINT}/${id}`);
            setItemToUpdate(resp.data);
            
          } catch (error) {
            console.log(error);
            history.push('/articulos'); //I think here is the problem
          }
        };
        fetchData();
      }
    }, [id]);
  
  return (
      &lt;Box mt={5}&gt;
          &lt;Paper elevation={7}&gt;
              &lt;Card className=&quot;card-root&quot; variant=&quot;outlined&quot;&gt;
                  &lt;CardContent&gt;
                    &lt;h2&gt;{id !== undefined ? 'Actualizar artículo' : 'Registrar artículo'}&lt;/h2&gt;
                    &lt;hr/&gt;
                    &lt;ItemForm
                      id={id}
                      item={itemToUpdate}
                    /&gt;
                  &lt;/CardContent&gt;
              &lt;/Card&gt;
          &lt;/Paper&gt;
      &lt;/Box&gt;
    )
  }
  </code></pre>