老师有问题关于componentWillReceiveProps

老师有问题关于componentWillReceiveProps

componentWillReceiveProps(nextProps) {
const id = nextProps.match.params.id;
axios.get('http://www.dell-lee.com/react/api/list.json?id=' + id)
.then(res => {
this.setState({
data: res.data.data
});
})
}

老师这个如果用

static getDerivedStateFromProps(props)方法写的话怎么写呢


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕久久 2021-12-02 13:11:21

同学你好,目前没办法使用static getDerivedStateFromProps(props)替代componentWillReceiveProps(nextProps)实现效果。虽然框架自身推荐使用static getDerivedStateFromProps,但是二者性质、外在表现不同,老师们测试过,替换后,效果实现不了,因此建议同学依旧使用componentWillReceiveProps完成效果。

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师