reactjs – 使用react-redux connect和redux数据的组件生命周期顺序

我们都知道构造函数 – > 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)

并且订单是否一致或取决于加载的数据?

反应和原生反应是不同的

并且可以根据PropType中的要求定义redux属性

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

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...