Search code examples
react-nativereduxreact-reduxreact-native-router-flux

React Native: How to check login status?


I am using react native router flex for navigation and I have 2 scene A and B,also using redux for storing state. if user login status is true the app will redirect to Page B else Page A. But I am unable to check the status.componentDidMount always getting false state.

Page A:

componentDidMount () {
if(status)
    {

      Actions.b();
    }

}


const mapStateToProps = ({userData}) => {

const {
status,
  } = userData;
  return {
    status,
  };

}

Let me know how to check login status.


Solution

  • Try to use componentWillReceiveProps. As soon as your status changes, your component will route to the next screen.

    componentWillReceiveProps(nextProps) {
      if(nextProps.status) {
        Actions.b();
      }
    }