react.js - React生命周期中的componentWillReceiveProps

查看:99
本文介绍了react.js - React生命周期中的componentWillReceiveProps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

http://reactjs.cn/react/docs/...
讲到componentWillReceiveProps的时候底下有一个注意事项
不太理解这段话的意思?
One common mistake is for code executed during this lifecycle method to assume that props have changed. To understand why this is invalid, read A implies B does not imply B implies A
There is no analogous method componentWillReceiveState. An incoming prop transition may cause a state change, but the opposite is not true. If you need to perform operations in response to a state change, use componentWillUpdate.

解决方案

意思是说只要上一级组件的render()发生,这个callback就会被调用。
如果props改变则会被调用 不能说明 调用的原因一定是props的改变,有可能不变。

这篇关于react.js - React生命周期中的componentWillReceiveProps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆