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
  • 2,078
  • 3
  • 19
  • 29
nathannewyen
  • 233
  • 6
  • 22

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
  • 474
  • 3
  • 13