我们都知道构造函数 – > componentwillMount – > componentDidMount是执行顺序.
现在,当redux发挥作用并尝试在组件生命周期中访问redux属性时.连接将执行的顺序是什么,以便数据可用生命周期方法忽略和数据更新到redux.可能性是
1. Connect (DATA AVAILABLE) -> constructor & componentwillMount & componentDidMount 2. constructor -> Connect (DATA AVAILABLE) -> componentwillMount & componentDidMount 3. constructor -> componentwillMount -> Connect (DATA AVAILABLE) -> componentDidMount 4. constructor -> componentwillMount -> componentDidMount -> Connect (DATA AVAILABLE)
并且订单是否一致或取决于加载的数据?
反应和原生反应是不同的
connect是一个包装组件的HOC,因此组件生命周期方法在连接生命周期之后.为了简单理解,您可以将连接写成这样写
const connect = (mapStatetoProps,mapdispatchToProps) => (Component) => { return class ReduxApp extends React.Component { // lifecycle of connect render() { return ( <Component {...mapStatetoProps(state)} /> ) } } }
现在,只要你的状态更新,connect就会浅显比较要返回给Component的道具列表,如果有更新,则更新道具,之后组件生命周期方法就像一个prop一样运行.
简而言之,最初的执行是
Connect (DATA AVAILABLE) -> constructor & componentwillMount & componentDidMount
一旦数据更新
Connect (DATA AVAILABLE) -> componentwillReceiveProps/getDerivedStateFromProps -> componentwillUpdate -> render -> componentDidUpdate
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。