When I'm passing history.push in a UseEffect function.
function Home(props) {
useEffect(() => {
const fetchData = async () => {
const response = await listingService.allListingDetails(data.listingId);
let tasksReceived = response.data.tasks;
let tasks = [...tasksReceived];
setTasks(tasks);
setListing(response.data);
if (tasks.length < 1) {
history.push({
pathname: "/firstpage",
state: {
listing: response.data,
},
});
return;
}
};
}, [changeState]);
}
index.js:1 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. at Home (http://localhost:3001/static/js/main.chunk.js:11116:79)
If I'm commenting the below line, the memory leak error doesn't come anymore.
if (tasks.length < 1) {
history.push({
pathname: "/firstpage",
state: {
listing: response.data,
},
});