Js.React.AddEventsOnRender

example

export class Toggle extends React.Component {
    constructor(props) {
        super(props);
        this.state = { isEnabled: true }
    }

    handleClick = () => {
        this.setState({ isEnabled: !this.state.isEnabled });
    }

    render() {
        return (
            <div>
                <button onClick={this.handleClick}>toggle</button>
                <div>{this.state.isEnabled ? 'Включено' : 'Выключено'}</div>
            </div>
        );
    }
}
This entry was posted in Без рубрики. Bookmark the permalink.