S
S
surerever2019-12-05 20:58:48
React
surerever, 2019-12-05 20:58:48

How to block a button for 2 seconds after it is pressed?

Hello. I ran into a problem: there are three buttons, when you click on any of them, you need to block (hang disabled) for 2 seconds all the buttons at once. How to do it ? I don’t understand exactly how to hang a lock for 2 seconds immediately after pressing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-12-05
@surerever

state = {
  disabled: false,
}

toggle(disabled) {
  this.setState(() => ({ disabled }));
}

onClick = () => {
  this.toggle(true);
  setTimeout(() => this.toggle(false), 2000);
}

<button disabled={this.state.disabled} onClick={this.onClick}>click me</button>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question