toggle function react js
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 (
<button onClick={this.handleClick}> {this.state.isToggleOn ? 'ON' : 'OFF'}
</button>
);
}
}
ReactDOM.render(
<Toggle />,
document.getElementById('root')
);
Also in JavaScript:
- how to stop the node server from running
- javascript get distinct values from array
- RFC8259 json
- decimal to base 32 javascript
- angular download blob pdf
- href javascript void
- react hooks delete item from array
- javascript find link by href
- onclick js
- javascript leave page warning
- what is eval in js
- javascript get data attribute value
- how to set time out in js
- postgresql nodejs
- Obtain smallest value from array of objects in Javascript
- change font size of angular material tooltip
- filter in react native
- react router command
- change inptu val
- js array .filter
- object literal javascript
- how to play sound on load js
- como diminuir quantidade de casas decimais javascript
- js replace space with underscore