CRA反应 - redux:componentWillReceiveProps被触发,但没有重新渲染

时间:2017-09-03 14:37:30

标签: reactjs redux react-redux

我使用create-react-app做一个连接到我的plex的最小应用程序,然后我做了登录表单。

到目前为止,我已经添加了react-router,redux和redux-saga,现在是时候对我的后端进行第一次POST了。

所有工作都按照需要工作,除了一件事:登录失败后容器不会重新渲染,但它会通过componentWillReceiveProps方法。

以下是发生的事情:

Here is what happened

事情是:商店已更改,因为如果我输入触发重新呈现的内容,则会显示错误消息。

我还可以看到,在redux DevTool中,商店确实存在来自服务器的错误。最后,服务器错误也在componentWillReceiveProps日志中。

我现在不知道该尝试什么。您可以在此处查看所有代码:https://github.com/kai23/askimovie/tree/add_plex_login

感谢您提供的任何帮助:)

1 个答案:

答案 0 :(得分:2)

取出这段代码或更新它,你的组件正在重新渲染,但当你想要进行更新时,它不是已经改变的状态它是你的道具。所以当道具改变时,这会运行并返回true,因为它一次只检查一个。它没有同时检查状态变化和道具变化。

  shouldComponentUpdate(nextProps, nextState) {
    return nextState.loginInput !== this.state.loginInput ||
      nextState.passwordInput !== this.state.passwordInput ||
      nextState.capsLockOn !== this.state.capsLockOn ||
      nextState.inputPasswordType !== this.state.inputPasswordType
    ;
  }
相关问题