1

I am having an issue when I try to get data api from my mongoose

Here is my code:

  const [products, setProducts] = useState([]);
  const getProductsAPI = () => {
    axios
      .get("http://localhost:8000/api/products")
      .then((res) => {
        setProducts(res.data);
        getProductsAPI();
      })
      .catch((err) => {
        console.log(err);
      });
  };

  useEffect(() => {
    getProductsAPI();
  }, [props]);

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.

Dennis Kozevnikoff
  • 1,654
  • 3
  • 14
  • 24
nathannewyen
  • 397
  • 4
  • 13

1 Answers1

3

The problem is the network request is resolved after the component unmounts. You can probably try some solution from this thread.

Danilo Gacevic
  • 444
  • 3
  • 13