Generation

generate functionWed, 25 Jan 2023

увеличить ширину div на 20px по клику на кнопку React

class MyButton extends React.Component { constructor(props) { super(props); this.state = { width: 200 }; } handleClick = () => { this.setState(({ width }) => ({ width: width + 20 })); }; render() { let style = { width: this.state.width + 'px' }; return ( <div> <button onClick={this.handleClick}>Click Me</button> <div style={style} className="box"> Hello! </div> </div> ); } } ReactDOM.render(<MyButton />, mountNode);

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant