search

Home  >  Q&A  >  body text

Execution order printed using react-redux - Stack Overflow

Why is the printed order 31232? Did I write it wrong?

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

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

巴扎黑巴扎黑2723 days ago653

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-12 09:33:31

    31232 is divided into two parts
    1. 312 First rendering component props——>constructor——>render
    2. 32 Component update props——>render

    reply
    0
  • Cancelreply