简单代码:
useEffect(() => {
AppState.addEventListener("change", handleChangeEvent);
return (() => {
console.log("REMOVING EVENT LISTENER");
AppState.removeEventListener("change", handleChangeEvent);
});
}, []);
const handleChangeEvent = () => {
console.log("EVENT LISTENER FIRING");
};
导航到新屏幕:
const changeScreen = () => {
return props.navigation.navigate("MainView", {})
}
到达新屏幕时:REMOVING EVENT LISTENER
触发。但是在这个新屏幕中,事件监听器仍在监听。
为什么不将其删除?