Reputation: 253
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.
Upvotes: 1
Views: 91
Reputation: 494
The problem is the network request is resolved after the component unmounts. You can probably try some solution from this thread.
Upvotes: 3