Reputation: 890
I have a function which I want to execute at the time of page load. First Time it works fine but if I go to the same page again It will not call the function. I understand that my Page is cached. How will I trigger some function on page load every time.
Upvotes: 2
Views: 151
Reputation: 9475
Depends on what you exactly mean by page load. If you mean that a different component gets rendered and then our original component gets rendered again, then it is these functions:
componentWillMount
render
componentDidMount
If you mean that you put your app in the background and then in the foreground again, you might not be able to rely on the react lifecycle functions at all (if no props are passed).
But you can to register a function that detects AppState
changes like this:
AppState.addEventListener('change', handleAppStateChange);
const handleAppStateChange = (nextAppState: AppStateStatus) => {
switch (nextAppState) {
case 'active':
break;
case 'background':
break;
default:
}
};
That way you get a callback when you put your app (and thus your Page into foreground again)
Upvotes: 2