zoukankan      html  css  js  c++  java
  • react初体验

    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);
    
  • 相关阅读:
    define和typedef
    keil5配置stm32库函数开发
    SPI、CAN、I2C
    flash,sram
    关于网络地址
    关于定时器、波特率、TH和TL值的计算
    关于串口工作方式
    ad各层
    AD快捷键
    OAuth2.0 微博登陆网站功能的实现(一)获取用户授权及令牌 Access Token
  • 原文地址:https://www.cnblogs.com/dkplus/p/8857495.html
Copyright © 2011-2022 走看看