Execute Functions on initial App opening - Where to put them?

Hello guys!

I was wondering where to put functions that must be executed on the opening of the app. Not on foregrounding. In my case a check whether the user is already signed in or not, so that I can redirect to an AuthenticationScreen if necessary.

The function for the retrieval of the ExponentPushToken, for example, is called in the navigation/RootNavigation.js by default, which feels kind of unintuitive…

What do you think and how do you handle those things?

Thanks in advance!

You could put it in componentWillMount of your root React component.

You’re absolutely right! That makes the most sense I guess. Thanks!

I have now tried to add the check for the authentication in the componentWillMount of the RootComponent, which works fine. But if the authentication has not been done, I need to redirect to the AuthenticationScreen. The issue is, that in the RootComponent I am not able to use this.props.navigation.navigate(…) to redirect. Do you know how to work this out?

1 Like

Without having a chance to see your code, it would be difficult to know if the navigation property is provided by the parent correctly. I would try to reorganize some of your code or read more into the docs for react-navigation to see how the property is provided in the first place.