我想在按鈕單擊時打開/渲染/顯示組件。我試圖通過改變狀態來做到這一點,但無法做到這一點。在按鈕單擊時渲染組件React ES6
我想渲染按鈕單擊組件。狀態發生變化,但組件不呈現。
export default class NewNav extends React.Component {
constructor(props) {
super(props);
this.state = {
date: new Date(),
login: false
};
this.handleClick = this.handleClick.bind(this);
}
handleClick(e) {
this.state.login = true;
}
render() {
const style = {
margin: 12
};
return (
<MuiThemeProvider>
<div className="top-bar">
<div className="top-bar-left">
<ul className="menu">
<li>
<RaisedButton
label="Sign Up"
style={style}
primary={false}
onClick={this.handleClick}
labelColor="#FFF"
backgroundColor="#00E676"/>
</li>
</ul>
</div>
<div className="top-bar-right">
<ul className="menu">
<li>
<RaisedButton
label="Log In"
primary={true}
className="btnLogin"
backgroundColor="#3AAA35"></RaisedButton>
</li>
<li>
<RaisedButton
label="Sign Up"
primary={false}
labelColor="#FFF"
backgroundColor="#00E676"/>
</li>
</ul>
{this.state.login
? <FirstPage/>
: null
}
</div>
</div>
</MuiThemeProvider>
);
}
}
非常感謝! –
不客氣。我很高興我可以幫助:) –