I have a piece of code in React Native that currently runs on app start. Within a class component constructor. It checks a bunch of conditions using the React Navigation state and then navigates somewhere.
class MyComponent<Props> {
constructor(props: Props) {
super(props);
// Some initialization code
}
}
I refactored it to use hooks using both useEffect and useLayoutEffect, but the code run now seems to happen only after the initial rendering, causing a flicker of another screen before the navigation takes place.
function MyComponent() {
useEffect(() => {
// Do some stuff
}, []);
return null;
}
Is there some equivalent to the class constructor that runs before rendering in function components?
SplashScreen.hide()when your app is ready - github.com/crazycodeboy/react-native-splash-screen