How do we call the specific type of action in reac

2020-03-31 05:31发布

问题:

How to call action using NavigationAction???

Here if the user doesn't have a token, it goes back to the initial page. I want to reset(initialize) the MainTabNavigator.

componentWillReceiveProps(nextProps) {

    if ( nextProps.token == undefined || _.isNil(nextProps.token) ) {
      const backAction = NavigationActions.back({
        key: null
      })
      nextProps.navigation.dispatch(backAction);

Here is MainTabNavigator. I added route to reset everything when 'MyCompleteReset' is triggered.

export default TabNavigator({ ........ });

const navigator = MainTabNavigator;
const defaultGetStateForAction = navigator.router.getStateForAction

navigator.router.getStateForAction = (action, state) => {
  if (action.type === 'MyCompleteReset') {
     // For your custom action, reset it all
     return defaultGetStateForAction(NavigationActions.init())
  }
  // Handle all other actions with the default handler
  return defaultGetStateForAction(action, state)
}

How do we call the MyCopmleteReset action???