0

I am learnin React Native and trying to build a small application. I am using below navigation to show login screen to user (if not logged in) or other tabs (if logged in)..

{isLoggedIn == null
          ? <Stack.Navigator>
              <Stack.Screen
                name="Login"
                options={{headerShown: false}}
                component={Login}
              />
            </Stack.Navigator>
          : <Tab.Navigator>
              <Tab.Screen
                name="Home"
.......
........ rest code

However this is working fine. But now how can I refresh the complete window (after login) and show the bottom tab navigation ?

Haren Sarma
  • 2,267
  • 6
  • 43
  • 72

1 Answers1

0

So you are asking how do you remember if the user is logged in? You'll need to use some form on persistent storage such as AsyncStorage. Then when the window reloads (or loads on a first time), load that storage with your app and properly set the isLoggedIn state.

Here is a thread on persistent storage:

What are my options for storing data when using React Native? (iOS and Android)

Likely you will have a Provider and Context to read from local storage and handle the status of a user being logged in or not. This is also true because many components throughout your app may need this information or username

When app opens -> Read storage (you may need to show a loading screen while this loads, it should be fast though). If user is logged in, set up credentials and proper state. If he's not, set it isLoggedIn to false.

Consumers can read this context whenever they need data like username or isLoggedIn.

Diesel
  • 5,099
  • 7
  • 43
  • 81
  • thanks, but I know how to remember if user is logged in. But the above code I have written is in App.js (main entry). I want to know how to reload the App.js (I mean main entry) after login is successful ... Now what is happening that, after login, I need to exit app and start again, then only bottom tab navigations are showing.. – Haren Sarma Aug 03 '20 at 15:13