`componentDidMount()` function is not called after navigation

后端 未结 9 1852
旧巷少年郎
旧巷少年郎 2020-12-09 03:38

I am using stackNavigator for navigating between screens. I am calling two API\'s in componentDidMount() function in my second activity. When i loa

9条回答
  •  渐次进展
    2020-12-09 03:51

    You want to perform something after every time navigating to a component using drawernavigator or stacknavigator ; for this purpose NavigationEvents fits better than componentDidMount .

    import {NavigationEvents} from "react-navigation";
    alert("Hello, I'm focused!")} />
    

    Note : If you want to do the task every time after focusing on a component using drawer navigation or stack navigation then using NavigationEvents is better idea. But if you want to do the task once then you need to use componenetDidMount .

提交回复
热议问题