React Update-无法从其他组件的FN主体内部更新组件

时间:2020-08-05 09:56:30

标签: reactjs react-native react-redux

我已经读过类似的问题,甚至开了一个github问题,但仍然无法理解这可能导致什么问题。

将RN版本从0.61升级到0.63后,我已经开始对我的应用程序抛出的几乎所有redux操作发出此警告。它们没有遵循任何模式,并且警告基本上在任何地方触发。

警告触发的一些示例:

UNSAFE_componentWillReceiveProps(nextProps) {
    ...
    if (this.props.vehicle?.id !== nextProps.vehicle?.id) {
      this.props.setNavigationCoordinates(null); // this is a redux action triggered from a lifecycle hook of a class component, warning appears
    }
UNSAFE_componentWillReceiveProps(nextProps) {
    ...
    if (this.props.auth.user?.location_id
      !== nextProps.auth.user?.location_id) {
      this.saveZone(this.state.configs.cities.find(
        (city) => city.id === nextProps.auth.user?.location_id,
      ));
    }

saveZone = (city) => {
    ...
    this.props.saveZones(city.nogo, bufferedZone, city.noparking, city.relocation); //redux action, warning triggered, although FN called only from the lifecycle hook.
  }
const renderVehicles = () => {
  ...
  props.updateDisplayedVehicles(vehiclesToDisplay.map((v) => v.props.vehicle)); // redux action, warning triggered
}

return (
  {(condition && renderVehicles()) || null}
)

这是我经常收到的警告:

Warning

任何有关此主题的帮助将不胜感激。我可能理解为什么在最后一种情况下会发出警告(尽管要解决它会涉及更改组件的工作方式),但我不明白为什么在前两种情况下会触发它。

谢谢!

0 个答案:

没有答案