1
我是React和編碼的新手。我試圖在同一個組件中渲染多個模態,但它們都在同一時間渲染,因此它看起來像所有的鏈接都在渲染上一個模態中的文本。
在此處,狀態設置:
React在同一組件中渲染多個模塊
class Header extends React.Component {
constructor() {
super();
this.state = {open:false}
this.openModal = this.openModal.bind(this);
this.closeModal = this.closeModal.bind(this);
this.handleModalChangeEnter = this.handleModalChange.bind(this, true);
this.handleModalChangeLogin = this.handleModalChange.bind(this, false);
}
openModal() {
this.setState({open: true}); }
closeModal() {
this.setState({open: false}); }
render() {
而這裏的模式建設:
return (
<header style={home}>
<div style={hello}>
<img style={logo} src='public/ycHEAD.png'/>
<p style={slogan}>One Calendar for All of Yerevan's Tech Events</p>
</div>
<div style={subContainer}>
<ul style={modalDirectory}>
<Button onClick={this.openModal}
style={openButton}>
<li><a style={tabs}>Enter
</a></li>
</button>
<Modal style={modalCont}
isOpen={this.state.open}>
<button onClick={this.closeModal}
style={xButton}>x</button>
</Modal>
<button onClick={this.openModal}
style={openButton}>
<li><a style={tabs}>Login
</a></li>
</button>
<Modal style={modalCont}
isOpen={this.state.open}>
<p>Account</p>
<button onClick={this.closeModal}
style={xButton}>x</button>
</Modal>
是否應在空括號中的數值 - > openModal()& closeModal()?