Tôi đang cố gắng thiết lập React.jsứng dụng của mình để nó chỉ hiển thị nếu một biến tôi đã đặt là true.
Cách thức chức năng kết xuất của tôi được thiết lập trông như sau:
render: function() {
var text = this.state.submitted ? 'Thank you! Expect a follow up at '+email+' soon!' : 'Enter your email to request early access:';
var style = this.state.submitted ? {"backgroundColor": "rgba(26, 188, 156, 0.4)"} : {};
return (
<div>
if(this.state.submitted==false)
{
<input type="email" className="input_field" onChange={this._updateInputValue} ref="email" value={this.state.email} />
<ReactCSSTransitionGroup transitionName="example" transitionAppear={true}>
<div className="button-row">
<a href="#" className="button" onClick={this.saveAndContinue}>Request Invite</a>
</div>
</ReactCSSTransitionGroup>
}
</div>
)
},
Về cơ bản, phần quan trọng ở đây là if(this.state.submitted==false)phần (tôi muốn các divphần tử này hiển thị khi biến được gửi được đặt thành false).
Nhưng khi chạy cái này, tôi gặp lỗi trong câu hỏi:
Uncaught Error: Parse Error: Line 38: Các phần tử JSX liền kề phải được bọc trong một thẻ kèm theo
Vấn đề ở đây là gì? Và tôi có thể sử dụng những gì để làm cho công việc này?