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

前端之家收集整理的这篇文章主要介绍了reactjs – 使用react-redux connect和redux数据的组件生命周期顺序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们都知道构造函数 – > componentWillMount – > componentDidMount是执行顺序.

现在,当redux发挥作用并尝试在组件生命周期中访问redux属性时.连接将执行的顺序是什么,以便数据可用生命周期方法忽略和数据更新到redux.可能性是

  1. 1. Connect (DATA AVAILABLE) -> constructor & componentWillMount & componentDidMount
  2.  
  3. 2. constructor -> Connect (DATA AVAILABLE) -> componentWillMount & componentDidMount
  4.  
  5. 3. constructor -> componentWillMount -> Connect (DATA AVAILABLE) -> componentDidMount
  6.  
  7. 4. constructor -> componentWillMount -> componentDidMount -> Connect (DATA AVAILABLE)

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

反应和原生反应是不同的

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

connect是一个包装组件的HOC,因此组件生命周期方法在连接生命周期之后.为了简单理解,您可以将连接写成这样写
  1. const connect = (mapStateToProps,mapDispatchToProps) => (Component) => {
  2. return class ReduxApp extends React.Component {
  3. // lifecycle of connect
  4. render() {
  5. return (
  6. <Component {...mapStateToProps(state)} />
  7. )
  8. }
  9. }
  10. }

现在,只要你的状态更新,connect就会浅显比较要返回给Component的道具列表,如果有更新,则更新道具,之后组件生命周期方法就像一个prop一样运行.

简而言之,最初的执行是

  1. Connect (DATA AVAILABLE) -> constructor & componentWillMount & componentDidMount

一旦数据更新

  1. Connect (DATA AVAILABLE) -> componentWillReceiveProps/getDerivedStateFromProps -> componentWillUpdate -> render -> componentDidUpdate

猜你在找的React相关文章