How to disable button onclick in Reactjs?

Viewed 25849

I had a condition if the two textfield are the same it will proceed, if not then the button is disabled. I know I'm doing this wrong.

onSubmit() {
        debugger
        if  (this.state.password == this.state.password2)
            alert('same');
        else 
            alert('error');
            this.disable;
}
3 Answers

This will work Perfect. Try this

render() {
  const submitDisabled = password.length > 0
  return (
    // ...
      <button disabled={submitDisabled}>Submit</button>
    // ...
  )
}
Related