在mapStateToProps之后没有调用的是反应componentWillRecieveProps

时间:2017-06-15 00:00:57

标签: reactjs redux react-router

我有一个使用react router 4和redux的同构反应应用程序。我有一种情况,我有多个路由使用相同的组件(SectionFront)。该组件连接到redux商店。

我希望每当商店的位置更新时都会调用该组件的componentWillRecieveProps(),但永远不会调用它。

class SectionFront extends React.Component{


componentWillReceiveProps( nextprops ){
    console.log('next props... does not fire on location change');

}

render(){
    console.log('Render was called', this.props);

    return(
    <div>this is the section front</div>
    )
}

}



const mapDispatchToProps = {
loadSectionFront
}

const mapStateToProps = (state) =>{
console.log('This is called properly every time after the state changes', state);

return {
    sectionFront : state.sectionFront.payload,
    isLoading: state.sectionFront.loading,
    pathname: state.location.pathname
}
} 

export default connect(mapStateToProps, mapDispatchToProps)(SectionFront)

关于为什么componentWillReceiveProps()没有被触发的任何想法,即使道具正在更新并且仍然调用渲染功能?

0 个答案:

没有答案
相关问题