I am implementing login page using react native and redux. Here is my a sample code for my reducer. There are three type; types.SUBMIT\_LOGIN, types.CHANGE\_USERNAME, types.CHANGE\_PASSWORD. 

CHANGE\_USERNAME and CHANGE\_PASSWORD is working fine. But the problem is SUBMIT\_LOGIN.I guess it's because of async state changes. There there anyway to change state after using fetch() method??

```
export default function login(state = initialState, action = {}) {
  switch (action.type) {
    case types.SUBMIT_LOGIN: {
      let loginStatus = false;

      if (state.username != null && state.password != null
        && state.username.length > 0 && state.password.length > 0
        && state.username === state.password) {
        loginStatus = true;
      } else {
      let updatedErrMsg = '';
      fetch('https://staging-barrie.mpower.ca/mpower/mpp/weblogin2.action?username='+state.username+'&password='+state.password,
      {
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
        },
      }
      )
      .then((response) => response.json())
      .then((responseJson) => {
        if (responseJson.result === 'success') {
          loginStatus = true;
        } else {
          loginStatus = false;
          updatedErrMsg = 'Incorrect Username or Password.';
        }
          return {
            ...state,
            isLoggedIn: loginStatus,
            errorMsg: updatedErrMsg
          };
        });
      }
      return {
        ...state,
        isLoggedIn: loginStatus
      };

    }

  case types.CHANGE_USERNAME:
    return {
      ...state,
      username: action.username
    };

  case types.CHANGE_PASSWORD:
    return {
      ...state,
      password: action.password
    };

  default:
    return state;

```

}
}