The question is, for example, there are 4 buttons, when you click on a button, the text in it should change to "Open", now the problem is that if you click on 1 button, the text will change in all buttons, is there any An elegant solution for such a problem? I can not figure it out, thanks.
import React from "react"; import ReactDOM from "react-dom"; import "./styles.css"; class App extends React.Component { state = { open: false }; handleOpen = () => { this.setState({ open: !this.state.open }); }; render() { const { open } = this.state; return ( <div> <button onClick={this.handleOpen}> {open ? "Открыто" : "Закрыто"} </button> <button onClick={this.handleOpen}> {open ? "Открыто" : "Закрыто"} </button> <button onClick={this.handleOpen}> {open ? "Открыто" : "Закрыто"} </button> <button onClick={this.handleOpen}> {open ? "Открыто" : "Закрыто"} </button> </div> ); } } const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement);