Search code examples
reactjsreact-routerreact-nativereact-native-router-flux

How to navigate based on a condition in RNRF react native


I would like to navigate to new screen only if login is successful, I tried using {Actions.HomeScreen} inside if condition but it does not do anything.

here is the code:

async login() {
const res = await api.getLoginResult();
const status= res.status;
console.log('log'+status);
if(status==='success'){
  {Actions.HomeScreen;}
}

}

Solution

  • You've forgotten to actually invoke the function, it should be:

    async login() {
      const res = await api.getLoginResult();
      const status = res.status;
      console.log('log' + status);
      if(status === 'success') {
        Actions.HomeScreen(); // Note the parens ()
      }
    }