gpt4 book ai didi

javascript - 使用 React 16.3.2 时未调用 UNSAFE_componentWillReceiveProps

转载 作者:数据小太阳 更新时间:2023-10-29 06:14:17 25 4
gpt4 key购买 nike

我遵循了 https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path 中的建议在升级到 React 16.3.2 之后,我想将我们所有即将弃用的生命周期方法重命名为它们的 UNSAFE_ 等价物。

但是我注意到 UNSAFE_componentWillReceiveProps 根本没有被调用。当我将其改回 componentWillReceiveProps 时,它会起作用。任何想法为什么?

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

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

最佳答案

我发现了问题。 react-dom包也需要升级到16.3.2版本。

关于javascript - 使用 React 16.3.2 时未调用 UNSAFE_componentWillReceiveProps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50114868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com