最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - UNSAFE_componentWillReceiveProps not called when using React 16.3.2 - Stack Overflow

programmeradmin2浏览0评论

I followed the advice in .html#gradual-migration-path and after upgrading to React 16.3.2 I wanted to rename all our soon to be deprecated lifecycle methods to their UNSAFE_ equivalents.

However I noticed that UNSAFE_ponentWillReceiveProps is not called at all. When I change it back to ponentWillReceiveProps it works. Any ideas why?

class Chart extends React.Component<ChartProps> {
  chartContainer: SVGSVGElement;
  tooltip: HTMLDivElement;
  xScale: ScaleBand<string>;
  yScale: ScaleLinear<number, number>;

  UNSAFE_ponentWillReceiveProps(nextProps: Props) {
    ...
  }
...
}

I followed the advice in https://reactjs/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path and after upgrading to React 16.3.2 I wanted to rename all our soon to be deprecated lifecycle methods to their UNSAFE_ equivalents.

However I noticed that UNSAFE_ponentWillReceiveProps is not called at all. When I change it back to ponentWillReceiveProps it works. Any ideas why?

class Chart extends React.Component<ChartProps> {
  chartContainer: SVGSVGElement;
  tooltip: HTMLDivElement;
  xScale: ScaleBand<string>;
  yScale: ScaleLinear<number, number>;

  UNSAFE_ponentWillReceiveProps(nextProps: Props) {
    ...
  }
...
}
Share Improve this question edited May 1, 2018 at 10:34 Július Retzer asked May 1, 2018 at 10:23 Július RetzerJúlius Retzer 1,0751 gold badge11 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I found the issue. react-dom package needs to be upgraded to 16.3.2 version as well.

发布评论

评论列表(0)

  1. 暂无评论