So i am updating state in a useEffect hook and getting this error i dont how to use cleanup function if we use async/await syntax in a useEffect hooks
Error :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 %s.%s, a useEffect cleanup function,
const getToken = async () => {
const mytoken = await AsyncStorage.getItem("fb_token");
if (mytoken) {
navigation.navigate("Main", { screen: "Map" });
setToken(mytoken);
} else {
setToken(false);
}
};
getToken();
}, [navigation]);```
How to update state and use clean up function should i declare this function outside hook but if i do that how would i use that function as a clean up?