Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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中有条件地返回当前状态和设置状态?_Reactjs_Methods_State - Fatal编程技术网

Reactjs 如何在React中有条件地返回当前状态和设置状态?

Reactjs 如何在React中有条件地返回当前状态和设置状态?,reactjs,methods,state,Reactjs,Methods,State,我需要调用方法,在这里我可以返回当前状态并在特定条件下更改它。 我做错了什么 这是我的状态: this.state = { input: { amount: "20000", } } 这是我的方法: methodHandler = () => { const {input} = this.state; if(condition){ this.setState({inp

我需要调用方法,在这里我可以返回当前状态并在特定条件下更改它。 我做错了什么

这是我的状态:

  this.state = {
            input: {
                amount: "20000",
   }
  }
这是我的方法:

methodHandler = () => {
    const {input} = this.state;
    if(condition){
        this.setState({input: { ...this.state.input, amount: 55000}})
    }
    return input.amount
   
}
我试着这样称呼它:

<p>{this.methodHandler} </p>
{this.methodHandler}

我也试过:

 <p>{this.methodHandler()} </p>
{this.methodHandler()}

这是:

 <p>{() => this.methodHandler()} </p>
{()=>this.methodHandler()}


什么都不起作用

您需要使用大括号才能将数据嵌入jsx中

试着这样做:

{this.methodHandler}


参考资料:

很抱歉让大家困惑,我一直在用花括号让大家困惑,我一直在用花括号