使用react-redux打印的执行顺序

为何打印出来的顺序是31232?是不是我写的不对?

class Home extends Component {
    constructor(props) {
        super(props);
        console.log(1)
        this.props.actions.fetchTopics({type: 'excellent'})
    }
    render() {
        console.log(2)
        return (
            <div>
                xxx
            </div>
        );
    }
}

const mapStateToProps = state => {
    console.log(3)
    
    const { postsByReddit } = state
    let topics = [],
        results = postsByReddit['results']
        
    if (results)  topics = results.topics
    
    return {
        topics
    }
}

export default connect(
    mapStateToProps,
    mapDispatchToProps
)(Home);

clipboard.png

阅读 3.3k
1 个回答

31232分为两部分
一、312 第一次渲染组件props——>constructor——>render
二、32 组件更新props——>render

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题