My code below won't run the if statement, only the else.
SecureStore.getItemAsync('notFirstLaunch').then((value) => {
LaunchApp(value);
});
const LaunchApp = function (value) {
console.log(value);
if (value === "true") {
return (
<SafeAreaView forceInset={{ bottom: 0 }} style={{ flex: 1, backgroundColor: '#E65100' }}>
<Main />
</SafeAreaView>
);
}
else {
SecureStore.setItemAsync('notFirstLaunch', "true");
return (
<Walkthrough />
);
}
};
my console.log returns value = true but my if statement never runs only the else, please help!
I think there is an issue with the code that is happening in the
.thenblock. I can't put my finger on it but it seems to me that the return statements wouldn't affect the render.This is how I would refactor your component if I was planning on doing what you are doing. Obviously you'll change what is returned for each use case rather than the simplistic views that I have put in.
When the component mounts I call
firstLaunchCheckit then updates the state of the notFirstLaunch variable if the value that has been stored inSecureStoreequals "true" if it is the first launch it also sets the value in theSecureStore. The change in the state causes a re-render which then shows the correct view.