2021-01-24 React Test 2

by Ttt Yyy

HTML

<div id="root"></div>

Babel + JSX

class Component extends React.Component {
  constructor(props, context) {
    super(props, context)
    this.state = { active: false }
    this.onClick = this.onClick.bind(this)
  }

  onClick() {
    this.setState({ active: true })
  }

  render() {
    return <div>
      <button onClick={this.onClick}>Click me</button>
      <p>Active: {this.state.active + ''}</p>
      <p>{Math.random()}</p>
    </div>
  }
}

ReactDOM.render(
  <Component />,
  document.getElementById('root')
)