Sometimes I get an error and the full error message is: "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."
What is the best way to fix this? This is my code:
const CustomRefresh = (props) => {
const {
isCurrent, isScheduled
} = props;
const [refreshing, setRefreshing] = useState(false);
const inventoryContext = useContext(inventoryContext);
const onRefresh = React.useCallback(async () => {
setRefreshing(true);
if (isCurrent) {
await inventoryContext.refreshToday();
}
if (isScheduled) {
await inventoryContext.refreshScheduled();
}
setRefreshing(false);
}, [refreshing]);
return (
<CustomRefresh refreshing={refreshing} style={style} onRefresh={onRefresh}>
{children}
</CustomRefresh>
);
};