UNPKG

@ozo/react-jazz

Version:

React 桌面端开发脚手架,基于CRA3,通用、开箱即用。

28 lines (22 loc) 771 B
// Demo.dom.js import React from 'react'; export default class CheckboxWithLabel extends React.Component { constructor(props) { super(props); this.state = { isChecked: false }; // bind manually because React class components don't auto-bind // https://reactjs.org/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding this.onChange = this.onChange.bind(this); } onChange() { this.setState({ isChecked: !this.state.isChecked }); } render() { return ( <label> <input type="checkbox" checked={this.state.isChecked} onChange={this.onChange} /> {this.state.isChecked ? this.props.labelOn : this.props.labelOff} </label> ); } }