使用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);

https://img1.mukewang.com/5c18a18d0001928a03120110.jpg

阿晨1998
浏览 633回答 1
1回答

慕侠2389804

31232分为两部分一、312 第一次渲染组件props——>constructor——>render&nbsp;二、32 组件更新props——>render
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript