Im new to react and started using hooks but I'm receiving warning on my console
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
I tried to fix it by defining a variable to check if its unmount or not(saw on another stackoverflow question. But it did not work.
here is my code
const Page1 = (props) => {
const [averageAPICallsPerDay, setAverageAPICallsPerDay] = useState(false);
const [org, setOrg] = useContext(OrgContext);
const [catalog, setCatalog] = useContext(CatalogContext);
const [didMount, setDidMount] = useState(false);
function getAverageAPICallPerDay() {
axios.get(`${ANALYTICS_BASEPATH}/${org}/${catalog}/analytics/calls/average`)
.then(res => setAverageAPICallsPerDay(res.data.data.averageCalls))
.catch(err => setAverageAPICallsPerDay('No records found'))
}
useEffect(() => {
setDidMount(true);
getAverageAPICallPerDay()
return(didMount)
}, [catalog, org])
return(
<Container>
<SubContainer>
<Row>
<Col><Card cardTitle="Total API Calls" totalCalls={averageAPICallsPerDay}/></Col>
</Row>
</SubContainer>
</Container>
);
};