import React from 'react';
import ReactDOM from 'react-dom';
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state= {
on: true
}
}
handleClick = () => {
// todo
this.setState({
on: !this.state.on
});
}
render() {
const { on } = this.state;
return (
<button
onClick={() => this.handleClick()}
>{on ? "Off": "On"}</button>
);
}
}
ReactDOM.render(
<Toggle />,
document.getElementById('root')
);
Created
May 5, 2020 22:38
-
-
Save mojaray2k/bf7703316588237b17708af83c9fd6db to your computer and use it in GitHub Desktop.
Create A Toggle Button in a React Class
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment