加载时AppLoading引发意外错误

时间:2019-04-29 09:22:40

标签: react-native

当从react-navigation v1迁移到react-navigation v3时,没有将导航状态存储在reducer中,我得到了这个错误

    react-navigation : ^3.0.9
    react-native: "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"

在迁移之前,我正在使用Navigation Reducer将状态存储在下面的代码中,来自NavigationRedux

    const appNavigationReducer = (state, action) => {
     let newState
      console.log('state',state)
      console.log('Action',action)

      if (action.type === 'LOGIN_STATE') {
        newState = AppNavigation.router.getStateForAction(loginState, state)
      }
      else {
        newState = AppNavigation.router.getStateForAction(action, state)
      }

      return newState || state
    }

   //RootContainer finishLoading function which is used by AppLoading

    _finishLoading = () => {
        const currentUser = store.getState().user.currentUser

        if (!!currentUser) {
          this.props.login()
        }

        this.setState({ ready: true })
      }


    //This is a render method of root container

     render () {
        return (
          <View style={ styles.applicationView }>
            { !this.state.ready &&
                <AppLoading
                  startAsync={ this._loadStuff }
                  onFinish={ this._finishLoading }
                  onError={ console.warn }
                />
            }
            { this.state.ready &&
              <View style={ styles.applicationView }>
                <ReduxNavigation loggedIn={ this.props.loggedIn }  />
                <Notification />
                <CheckInConfirmation />
              </View>
            }
          </View>
        )
      }

// root容器类的mapDispatchToProps

    const mapDispatchToProps = (dispatch) => ({
      login: () => dispatch({ type: 'LOGIN_STATE' })
    })

0 个答案:

没有答案