0
我陷入了有點奇怪的情況,我使用ReactJS。我有標題容器,標題欄,標題容器。標題容器具有導航欄。點擊它會影響標題欄。我正在使用反應路由器進行導航。我正在使用componentDidMount
生命週期方法。如何停止更新reactjs
標題容器加載時僅觸發一次的問題。所以我用componentDidUpdate
。但是當我將標題欄組件添加到標題容器時發生了這個問題。所以現在我的componentDidUpdate
無限循環運行。我試圖使用shouldComponentUpdate(nextProps, nextState)
,但我不知道什麼條件把它返回false。
export class TitleContainer extends React.Component {
componentDidMount() {
this.props.dispatch(fetchDetail(this.props.match.params.program_id))
}
componentDidUpdate(prevProps, prevState) {
this.props.dispatch(fetchDetail(this.props.match.params.id))
}
shouldComponentUpdate(nextProps, nextState){
console.log("current props",this.props)
console.log("next props",nextProps)
// if(this.props.name == nextProps.name)
// return false;
return true;
}
render() {
console.log("data in contaner", this.props)
return (
<div>
<Title name = { this.props.name }
/>
</div>
)
}
}
const mapStateToProps = (state) => {
console.log("update state", state)
return {
programProfileData: state.DetailReducer.Details,
name: state.DetailReducer.name
}
}
export default connect(mapStateToProps)(TitleContainer)
問題我在第一次使用它時遇到了這個問題,但是如果你從下拉列表中選擇任何其他程序,它也不會呈現 – LowCool