即使简化器中的状态已明显更改,componentWillReceiveProps也不会触发

时间:2018-11-18 02:06:20

标签: react-native redux react-native-ios

我知道在SO上针对同一问题有很多答案,但是我已经通读了它们,似乎都没有解决我所看到的问题的方法。真的需要有人的帮助。

场景:我们在App Store中有一个现有的React Native应用(v0.42.3),一切都很好。今天,由于第3方库错误,我们需要删除node_modules并进行重建。已经完成,没有问题。该应用程序启动正常。但是现在由于某种原因,登录流程中断了,它“似乎”归因于Redux。它只是一个简单的登录流程。希望这里是所有详细信息:

用户点击登录->呼叫操作创建者->成功->呼叫减少器->调用mapStateToProps(state)的更新状态

我无法解决的问题-是: 1)mapStateToProps正在触发,您可以看到所需的属性(displayLoginModal)从true更改为false

2)componentWillReceiveProps未触发,这中断了应用流程

动作创建者

 ..auth worked fine, then call..

 dispatch({
        type: LOGIN_USER_SUCCESS,
        payload: { user: userInfo },
        greeting: isNewUser ? "welcome" : "hi",
        isLoggedIn: true,
        waitingForLoginCompletion: false
      });

 dispatch({ type: SHOW_LOGIN_MODAL, display: false });

减速器

case SHOW_LOGIN_MODAL:
  return {
    ...state,
    displayLoginModal: action.display
  };

  case LOGIN_USER_SUCCESS:
   return {
     ...state,
     user: action.payload,
     greeting: action.greeting,
     error: "",
     loginUserError: "",
     faceBookLoading: false,
     googleLoading: false
  };

“接收/收听组件(LoginView)

am使用@connect装饰器

这是mapStateToProps函数:

function mapStateToProps(state) {
  console.log(state) <== **IMPORTANT. this IS showing that the prop has changed
  const {
    email,
    password,
    error,
    ... etc...
    displayLoginModal   <== this is the prop that IS changing (from    true, to false)
  } = state.auth;

  return {
    ..snip.. other props etc...
    displayLoginModal,    <== returning it here
    isConnectedToFirebase
  };
}

....
@connect(
mapStateToProps,
{
    updateTermsOfUseAndPrivacy,
    emailChanged,
    passwordChanged,
    errorMessageChanged,
    loginUserWithEmail,
    loginUserWithFacebook,
    facebookLogin,
    googleLogin,
    loginUserWithGoogle,
    resetUserPassword,
    setTermsOfUseAndPrivacy,
    logout,
    resetPasswordComplete
  }
)
export default class LoginView extends Component {
 ... etc

再说一次-甚至以为mapStateToProps正在触发并正确显示属性值的更改-由于某些奇怪的未知原因,我componentWillReceiveProps没有触发。

为什么?目前这对我们来说是一个严重的阻碍,非常感谢您的帮助和建议。希望我错过了一些明显的事情。

1 个答案:

答案 0 :(得分:0)

好的-已排序。这里的问题与Redux无关。这是由于缺少路线。并不是说任何隐秘/不存在的错误消息都与此有关。我承担责任,但是我会说我正式不再是React Native的粉丝。死亡减少一千。

相关问题