gpt4 book ai didi

javascript - 在渲染内 react 三元

转载 作者:行者123 更新时间:2023-11-28 17:23:48 28 4
gpt4 key购买 nike

嗨,我尝试在渲染内部使用三元条件,但遇到一些错误,这是我的代码:

render() {
return (
<div>
<div className="isoInputWrapper">
<Input
ref={email => (this.email = email)}
size="large"
placeholder="Email"
value={this.state.email}
onChange={event => {
this.setState({ email: event.target.value });
}}
/>
</div>

<div className="isoInputWrapper">
<Input
type="password"
size="large"
placeholder="Senha"
value={this.state.password}
onChange={event => {
this.setState({ password: event.target.value });
}}
/>

{this.props.signup?}

<Input
type="password"
size="large"
placeholder="Senha"
value={this.state.password}
onChange={event => {
this.setState({ password: event.target.value });
}}
/>

{: do something }

最佳答案

大括号需要在三元组之前打开,并在三元组结束之后关闭:

{this.props.signup ?

<Input
type="password"
size="large"
placeholder="Senha"
value={this.state.password}
onChange={event => {
this.setState({ password: event.target.value });
}}
/>

: <div>test</div> }

关于javascript - 在渲染内 react 三元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007123/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com