Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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 js async函数_Reactjs - Fatal编程技术网

Reactjs 类中的react js async函数

Reactjs 类中的react js async函数,reactjs,Reactjs,我现在有一个名为resetThenSet的函数,如下所示 resetThenSet = (id, arrayId, title) => { let size = [...this.state[arrayId]] blah blah blah } 此resetthenSet方法是从我的渲染方法调用的,如下所示: <Dropdown title="Size" arrayId="selectProduct"

我现在有一个名为resetThenSet的函数,如下所示

resetThenSet = (id, arrayId, title) => {
  let size = [...this.state[arrayId]]
  blah blah blah
}
此resetthenSet方法是从我的渲染方法调用的,如下所示:

        <Dropdown
          title="Size"
          arrayId="selectProduct"
          list={this.state.selectProduct}
          resetThenSet={this.resetThenSet}
        />
这在我的控制台中给了我一个错误

Invalid argument passed as callback. Expected a function. Instead received: [object Promise]
这似乎与范围有关,所以我想我应该为其添加绑定:

this.resetThenSet = resetThenSet.bind(this);
这给了我一个错误

resetThenSet is not defined
有没有一种简单的方法可以将react中的fat-arrow函数更改为异步函数

我检查了这个,但没有任何帮助:

类Youdidtellus扩展组件{
异步重置设置(id、arrayId、标题){
让size=[…this.state[arrayId]]
//废话废话
}
render(){
返回(
this.resetThenSet()}
/>
...
类youdidtellus扩展组件{
异步重置设置(id、arrayId、标题){
让size=[…this.state[arrayId]]
//废话废话
}
render(){
返回(
this.resetThenSet()}
/>
...
尝试这个,因为您绑定到一个未声明的函数。这就是它抛出错误的原因

您可以阅读更多关于“为什么要将函数绑定到此”

尝试这个,因为您绑定到一个未声明的函数。这就是它抛出错误的原因

您可以阅读更多关于“为什么要将函数绑定到此”

>代码> this .ReStutStase.Band(this);< /代码>。也可以通过使用箭头函数语法来避免绑定。AsiNC ReStEnTeSET =(ID,RayayID,title)= {LeSeab[=……….Stase[AlrayID] ] //BLAH BLAH BLA} <代码> this .ReStTeSETSET= .ReStTestSt.绑定(this)也可以考虑检查这一点:也可以避免使用箭头函数语法来绑定。Asic ReStEnTeSET =(ID,RayayID,title)= {Lead Simule=…………[状态[ARAYID] ] / /BLAH BLAH BLAH}避免将新闭包传递给子组件。每次父组件呈现时,都会创建一个新函数并将其传递给输入。这是一个React组件,这将自动触发它重新呈现,而不管它的其他支柱是否已实际更改。避免将新闭包传递给子组件。每次父组件呈现nt渲染时,将创建一个新函数并将其传递给输入。这是一个React组件,它将自动触发它重新渲染,而不管它的其他道具是否已实际更改。
resetThenSet is not defined
class youDidntTellUs extends Component {

async resetThenSet(id, arrayId, title){
let size = [...this.state[arrayId]]
  //blah blah blah
}

render(){
return (
  <Dropdown
      title="Size"
      arrayId="selectProduct"
      list={this.state.selectProduct}
      resetThenSet={() => this.resetThenSet()}
    />
...
this.resetThenSet = this.resetThenSet.bind(this);