React条件渲染
傳參判斷
class LoginControl extends React.Component {constructor(props) {super(props);this.handleLoginClick = this.handleLoginClick.bind(this);this.handleLogoutClick = this.handleLogoutClick.bind(this);this.state = {isLoggedIn: false};}handleLoginClick() {this.setState({isLoggedIn: true});}handleLogoutClick() {this.setState({isLoggedIn: false});}render() {const isLoggedIn = this.state.isLoggedIn;let button = null;if (isLoggedIn) {button = <LogoutButton onClick={this.handleLogoutClick} />;} else {button = <LoginButton onClick={this.handleLoginClick} />; }return (<div><Greeting isLoggedIn={isLoggedIn} /> {button}</div> );} }ReactDOM.render(<LoginControl />,document.getElementById('example') );?
轉(zhuǎn)載于:https://www.cnblogs.com/shui1993/p/9959989.html
總結(jié)
- 上一篇: 阿里2500万美元战略投资“神工007”
- 下一篇: ocr移动端车牌识别技术特点