The onclick event on the button does not work for the first click, and it works well from the second. Why is this?

state={bank:bankOne};
  handleButtonClick=()=>{
   let button=document.getElementById('button');
   button.style.backgroundColor==='lightcoral'?button.style.backgroundColor='lightgreen':
   button.style.backgroundColor='lightcoral';
   this.state.bank===bankOne? this.setState({bank:bankTwo}):
   this.setState({bank:bankOne});
  }

Is this a javascript challenge?

yes. It is. It’s a react question.

The style does not change for the first click as well. Everything works fines from the second, both the state and the style.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.