Reactjs 如何在切换时显示输入字段?

Reactjs 如何在切换时显示输入字段?,reactjs,Reactjs,我想在切换时显示输入字段。切换正在工作,但未显示输入字段。我怎样才能做到这一点?我已经试过了,但是没有显示输入字段 代码如下: handleToggle=()=>{ console.log('In handletoggle') 这是我的国家({ 基于里程碑的支付:!this.state.milestone基于里程碑的支付 }) } 百分比率=()=>{ 百分率 {this.handleChange(e,“百分比率”)} /> { 此.state.percent\u rate\u错误&&( {th

我想在切换时显示输入字段。切换正在工作,但未显示输入字段。我怎样才能做到这一点?我已经试过了,但是没有显示输入字段

代码如下:
handleToggle=()=>{
console.log('In handletoggle')
这是我的国家({
基于里程碑的支付:!this.state.milestone基于里程碑的支付
})
}
百分比率=()=>{
百分率
{this.handleChange(e,“百分比率”)}
/>
{
此.state.percent\u rate\u错误&&(
{this.state.percent\u rate\u error}
)
}
}
togglePayment=()=>{
const{milestone_-based_-payment}=this.state;
console.log('togglepayment')
返回(
this.handleToggle()}
样式={{光标:“指针”}}/>
);
}

您可以在真/假条件下显示/隐藏输入字段,如下所示:

showHideInput() {
    if(this.state.milestone_based_payment === true) {
        return <input />
     }
}
// and call the method in other method 
// or inline condition
(this.state.milestone_based_payment === true) ? <input /> : <React.Fragment />
showHideInput(){
if(this.state.milestone_-based_-payment===true){
返回
}
}
//并在其他方法中调用该方法
//或内联条件
(this.state.milestone_-based_-payment===true)?:

我看不到您试图在何处切换输入的可见性。“切换正在工作”是什么意思?你在哪里尝试?你的问题和代码一点也不清楚!请给我们一个完整的代码示例。如果您的输入字段是
InputBase
,并且您想使用
milestone\u-based\u-payment
作为
true或false
条件,请尝试以下操作:
{(this.state.milestone\u-based\u-payment)?():null}
只要在类
{(this.state.milestate_-based_-payment)?this.percentRate():null}
它在jsx上不起作用。您不能使用if语句的通用语法!您可以在jsx中使用true-false速记实现它(this.state.milestate_-based_-payment==true)?:
showHideInput() {
    if(this.state.milestone_based_payment === true) {
        return <input />
     }
}
// and call the method in other method 
// or inline condition
(this.state.milestone_based_payment === true) ? <input /> : <React.Fragment />