Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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
Reactjs React with Redux:更新存储后调用函数_Reactjs_Redux_React Redux - Fatal编程技术网

Reactjs React with Redux:更新存储后调用函数

Reactjs React with Redux:更新存储后调用函数,reactjs,redux,react-redux,Reactjs,Redux,React Redux,如何确保存储已更新,并且我可以调用需要更新存储的函数?更新存储后。您可以在componentWillReceiveProps中获得已连接组件内的更新全局状态,如下所示: componentWillReceiveProps(nextProps){ //invoke function with updated store //this.foo(nextProps) console.log(this.props); // prevProps console.log(nextProps)

如何确保存储已更新,并且我可以调用需要更新存储的函数?

更新存储后。您可以在
componentWillReceiveProps
中获得已连接组件内的更新全局状态,如下所示:

componentWillReceiveProps(nextProps){
  //invoke function with updated store
  //this.foo(nextProps)
  console.log(this.props); // prevProps
  console.log(nextProps); // currentProps after updating the store
  }
您还可以使用
getDerivedStateFromProps

 static getDerivedStateFromProps(nextProps, prevState) {
   }

一旦你更新了商店。您可以在
componentWillReceiveProps
中获得已连接组件内的更新全局状态,如下所示:

componentWillReceiveProps(nextProps){
  //invoke function with updated store
  //this.foo(nextProps)
  console.log(this.props); // prevProps
  console.log(nextProps); // currentProps after updating the store
  }
您还可以使用
getDerivedStateFromProps

 static getDerivedStateFromProps(nextProps, prevState) {
   }

我用shouldComponentUpdate

shouldComponentUpdate(nextProps) {
  if(this.props.someArray.length !== nextProps.someArray.length) {
    /* some function here */
    return true;
  }
  return false;
} 

我用shouldComponentUpdate

shouldComponentUpdate(nextProps) {
  if(this.props.someArray.length !== nextProps.someArray.length) {
    /* some function here */
    return true;
  }
  return false;
} 

使用生命周期方法?使用生命周期方法?使用此方法不用于使用更新状态。实际上,建议在要停止不可测量的重新渲染的位置使用。但我相信我们应该构建我们的应用程序,就像没有不必要的重新渲染一样。在React文档中,关于shouldComponentUpdate();“返回false以告知可以跳过React更新”。。查看文档。想问任何问题都可以。@Sakhi Mansoor,那么在商店更新之后,componentDidUpdate(prevProps)可能是调用方法的好地方吗?请检查我上面的答案,您可以在这两种方法中获得更新的商店内道具。每个生命周期都有不同的语义。通常我们认为这些事情是理所当然的,当我们的应用程序增长时,它们会成为一种巨大的痛苦。Ok@Sakhi MansoorThis不是用来利用更新状态的。实际上,建议在要停止不可测量的重新渲染的位置使用。但我相信我们应该构建我们的应用程序,就像没有不必要的重新渲染一样。在React文档中,关于shouldComponentUpdate();“返回false以告知可以跳过React更新”。。查看文档。想问任何问题都可以。@Sakhi Mansoor,那么在商店更新之后,componentDidUpdate(prevProps)可能是调用方法的好地方吗?请检查我上面的答案,您可以在这两种方法中获得更新的商店内道具。每个生命周期都有不同的语义。通常我们认为这些事情是理所当然的,当我们的应用程序增长时,它们会成为巨大的痛苦