【问题标题】:Expected instance props to match memoized props in React 16预期的实例道具与 React 16 中的记忆道具匹配
【发布时间】:2019-04-15 19:22:12
【问题描述】:

我正在从react 版本15 升级到16 (16.6.1),我在控制台中看到了这个警告,我应该担心吗?

Warning: Expected instance props to match memoized props before componentDidUpdate. This is likely due to a bug in React. Please file an issue.

我无法真正提出问题,因为我无法查明问题,而且这不是我要分享的代码。我在网上找不到有关此问题的任何信息。

我应该担心吗?我应该让它溜走吗?

【问题讨论】:

  • 你能发布一些示例代码吗?或者至少提供一个触发相同警告的示例。
  • @mattcarlotta 我可以重现警告,see my comment on github issues

标签: javascript reactjs frontend web-frontend


【解决方案1】:

我花了好几天才解决。问题是 this.state 是我的地址字段的局部变量 ref。

ref={ref => (this.state = ref)} // 错误行

【讨论】:

    【解决方案2】:

    查看 this issue report 中的重现案例,这是因为特定库(在该示例中为 react-css-modules)覆盖了 React 组件中的 this.props 对象。

    这从未得到支持,并可能导致其他问题。如果您必须依赖它,here 描述了一种可能的解决方法。

    【讨论】:

      猜你喜欢
      • 2020-06-05
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2018-11-14
      • 2018-10-12
      相关资源
      最近更新 更多