function Guest() {
return (
<h1>pls login in</h1>
);
}
function User() {
return (
<h1>hi, user</h1>
);
}
function Check(props) {
const isLogin = props.isLogin;
if (isLogin) {
return <User/>
}else {
return <Guest/>
}
} function LoginButton(props) {
return (
<button onClick={props.onClick}>login</button>
);
}
function LogoutButton(props) {
return (
<button onClick={props.onClick}>logout</button>
);
} class LoginControl extends React.Component {
constructor(props) {
super(props);
this.handleLogin = this.handleLogin.bind(this);
this.handleLogout = this.handleLogout.bind(this);
this.state = {
isLogin: true
}
}
handleLogin() {
this.setState({isLogin: true});
}
handleLogout() {
this.setState({isLogin: false});
}
render() {
const isLogin = this.state.isLogin;
let button = null;
if (isLogin) {
button = <LogoutButton onClick={this.handleLogout}/>
}else {
button = <LoginButton onClick={this.handleLogin}/>;
}
return (
<div>
<Check isLogin = {this.state.isLogin}/>
{button}
</div>
);
}
} let root = document.getElementById('root');
ReactDOM.render(<LoginControl/>, root);

最新文章

  1. 解决错误: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
  2. TC79
  3. TextView中gravity属性值测定
  4. 第一次写python
  5. DIV内英文或者数字不换行的问题 解决办法
  6. OpenJudge/Poj 1657 Distance on Chessboard
  7. 查看源码Vim+Cscope
  8. 二、Mp3帧分析(标签帧)
  9. 使用requests模块爬虫
  10. protobuf 编码实现解析(java)
  11. JAVA_SE基础——9.基本数据类型间的转换
  12. SpriteKit关于SKScene中的渲染Loop
  13. Troubleshooting 10g and 11.1 Clusterware Reboots (文档 ID 265769.1)
  14. 问题:页面输出正常,php写入sqlserver乱码/空白。
  15. 1.Float精度在JS的解决方法
  16. Makefile中通过sed命令生成文件系统的selinux的配置文件vendor_filesystem_config.txt
  17. GT--记录android app消耗的cpu/内存/流量/电量
  18. .net core2.1 - ef core数据库迁移,初始化种子数据
  19. 再读vue2.0
  20. 牛客网PAT乙级(Basic Level)真题-数素数 (20)

热门文章

  1. oracle-java7-installer安装java失败之后的处理
  2. MongoDB入门(4)- MongoDB日常操作
  3. linux查找进程id端口占用和杀死进程
  4. Hadoop window win10 基础环境搭建(2.8.1)
  5. LightOJ 1375 - LCM Extreme 莫比乌斯反演或欧拉扩展
  6. [洛谷3457][POI2007]POW-The Flood
  7. sqlserver 个人整理
  8. iOS 隐藏导航栏下的黑线
  9. asp.net 权限管理系统
  10. 【Foreign】光 [莫比乌斯反演]