javascript - 使用react-redux打印的执行顺序
本文介绍了javascript - 使用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);
解决方案
31232分为两部分
一、312 第一次渲染组件props——>constructor——>render
二、32 组件更新props——>render
这篇关于javascript - 使用react-redux打印的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文