[reactjs] [as shown] the modified state will not take effect immediately

the desired effect is to empty state.text (that is, the contents of input should be emptied), but not

.
class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      list: this.props.list || [],
      text: ""
    }
  }
  renderReminder() {
    return <ul className="list-group col-sm-8 mt-2">
      <li className="list-group-item">
        <div>text</div>
        <div><em>time</em></div>
      </li>
    </ul>
  }
  render() {
    return (
      <div className="App">
        <div className="className">Reminder Pro</div>
        <div className="form-inline">
          <div className="form-group mr-2">
            <input
              type="text"
              className="form-control"
              placeholder="..."
              onChange={(event) => this.setState({ text: event.target.value })}
            />
          </div>
          <button
            type="button"
            className="btn btn-success"
            onClick={() => {
              if (!this.state.text) return;
              this.props.addReminder(this.state.text);
              this.setState({
                text: ""
              });
            }}
          ></button>
        </div>
        <ul className="list-group col-sm-8 mt-2">
          {
            this.props.list.map((item) => <li className="list-group-item" key={item.id}>
              <div>{item.text}</div>
              <div><em>{item.create_time}</em></div>
            </li>)
          }
        </ul>
      </div>
    );
  }
}

Apr.01,2021

bind input to value

             <input
              type="text"
              value={this.state.text}
              className="form-control"
              placeholder="..."
              onChange={(event) => this.setState({ text: event.target.value })}
            />

it is recommended that the landlord first learn about controlled and uncontrolled components .

if you want to achieve the desired effect, you need to bring the component under control by adding value to input .

<input
  type="text"
  className="form-control"
  placeholder="..."
  value={this.state.text}
  onChange={(event) => this.setState({ text: event.target.value })}
/>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3723d-2b7e9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3723d-2b7e9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?