Annoying warning is logged in console while loading the home screen. How can I remove this warning, I have created a const isMounted = useRef(null);
How does it work and where should i need to use this ?
isMounted.current = true;
return () => {
// executed when unmount
isMounted.current = false;
}
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. in Home (created by Context.Consumer) in Route (at App.js:21) in Switch (at App.js:20) in Router (created by BrowserRouter) in BrowserRouter (at App.js:17) in App
Home.js
const isMounted = useRef(null);
useEffect(() => {
const fetchData = async () => {
try {
const res = await Axios.get('http://localhost:8000/service/players');
setPlayerList(res.data.players);
setSearchResults(res.data.players);
showDeleteIcon(privilege);
} catch (e) {
console.log(e);
}
}
fetchData();
}, []);