I'm trying to learn why it's necessary to use useCallback
in this situation:
function MyComponent() {
const navigation = useContext(NavigationContext);
const redirect = useCallback(() => {
navigation.navigate("Home");
});
useEffect(() => {
redirect();
}, [redirect]);
}
I can't use navigation
directly inside useEffect()
and also I can't refer the function without useCallback()
. I don't know why I can use other objects like Firebase Context (from a Firestore instance) without any problem inside useEffect, but I can't use navigation
directly.
question from:
https://stackoverflow.com/questions/66067987/trying-to-understand-the-use-of-usecallback-in-this-situation-with-react-navigat 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…