I've been receiving an error message in the developer console suggesting a type of memory leak tied to my useEffect()
's. The error suggests to develop some form of 'cleanup' function, but I'm not sure why this is occurring in the first place or how to go about developing this. How should I approach this? My useEffect()
functions in question are below:
useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => window.removeEventListener('scroll', handleScroll);
}, []);
useEffect(() => {
if (!isFetching) return;
fetchMoreListItems();
}, [isFetching]);
useEffect(() => {
let mounted = true;
if (!props.resource) return;
props.resource
.follow('item-collection')
.followAll('item')
.then(resources => {
if (mounted) {
setItems(resources);
}
})
.catch(err => console.error('Error fetching resources: ' + err));
return () => mounted = false;
}, [itemResource]);