📅  最后修改于: 2022-03-11 15:04:15.395000             🧑  作者: Mango
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make `this` work in the callback this.handleClick = this.handleClick.bind(this); }
handleClick() { this.setState(state => ({ isToggleOn: !state.isToggleOn })); }
render() {
return (
);
}
}
ReactDOM.render(
,
document.getElementById('root')
);