console
const $ = React.createElement
class CheckBox extends React.Component {
componentWillReceiveProps(nextProps) {
if (this.checkbox) {
this.checkbox.checked = nextProps.checked
}
}
input (checkbox) {
this.checkbox = checkbox
}
render () {
const { onClick } = this.props
return $('input', {ref: this.input.bind(this), type: 'checkbox', onClick})
}
}
class CheckAll extends React.Component {
constructor (props) {
super(props)
this.state = {
checkall: false
}
}
onClick () {
this.setState({
checked: !this.state.checked
})
}
render () {
const { checked } = this.state
return $('div', {},
$('p', null, $('label', null, $(CheckBox, {
onClick: this.onClick.bind(this),
checked
}), $('span', {key: '2'}, '全选'))),
$(CheckBox, {checked}), 1,
$(CheckBox, {checked}), 2,
$(CheckBox, {checked}), 3,
$(CheckBox, {checked}), 4,
$(CheckBox, {checked}), 5,
)
}
}
ReactDOM.render(
$(CheckAll),
document.getElementById('app')
)
<script src="https://cdn.bootcss.com/react/16.2.0/umd/react.development.js"></script>
<script src="https://cdn.bootcss.com/react-dom/16.2.0/umd/react-dom.development.js"></script>
<div id="app"></div>