Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 渲染后未调用componentDidUpdate_Javascript_Reactjs_React Router - Fatal编程技术网

Javascript 渲染后未调用componentDidUpdate

Javascript 渲染后未调用componentDidUpdate,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我需要连接到组件更新事件,以获取新数据。因此,我写了这样的东西: ... constructor(props) { super(props); const values = queryString.parse(this.props.location.search), type = values['type']; this.props.loadChallengeDetails(type); } shouldComponentUpdate() { console.log('

我需要连接到组件更新事件,以获取新数据。因此,我写了这样的东西:

...
constructor(props) {
  super(props);
  const values = queryString.parse(this.props.location.search),
    type = values['type'];
  this.props.loadChallengeDetails(type);
}

shouldComponentUpdate() {
  console.log('shouldComponentUpdate');
  /* if (this.props.location.search !== nextProps.location.search) {
    console.log('should reload report');
    const values = queryString.parse(nextProps.location.search),
      type = values['type'];
    this.props.loadChallengeDetails(type);
  } */
  return true;
}

componentDidUpdate(prevProps) {
  console.log('componentDidUpdate');
  if (this.props.location.search !== prevProps.location.search) {
    console.log('should reload report');
    const values = queryString.parse(this.props.location.search),
      type = values['type'];
    this.props.loadChallengeDetails(type);
  }
}

render() {
  console.log('details:', this.props.details);
...
如果您愿意,此页面/视图是“母版”页面的“详细信息”。根据查询中传递的
type
的值,它会获取一些数据

第一次渲染时效果很好。调用了
shouldComponentUpdate
componentdiddupdate
生命周期方法。然而,当我返回查看另一条记录的详细信息时,它会显示过时的数据。控制台日志在渲染内部打印
详细信息
,但不调用
shouldComponentUpdate
componentDidUpdate


我做错了什么?请告知。

什么是
this.props.loadChallengeDetails
do?从redux商店加载
this.props.details
。您是否缺少组件的
withRouter
包装器?@madebydavid为什么
withRouter
甚至重要,如果
render()
被调用?@IgorShmukler-
此.props.location
仅当您使用带路由器的
时才会设置