1

This is my code for react

handleRemoveClick = material => {
  let idMaterial = material.material_id;
  if(this.state.operation === 0){
    this.setState( { previewShowAlertRemoveProduct : true })
    }
    this.setState( { operation : 1, material_id : idMaterial})
}



handleEndOrder(){
  if(this.state.operation === 0){
    this.setState( { previewShowAlertRemoveProduct : true })
    }
    this.setState( { operation : 2})
}

This is for Render the View:

  <button class="btn btn-xs btn-danger pull-right"  onClick={e => this.handleRemoveClick(material)}>x</button>

How to fix this ? onClick it's not working at all I have binded in the constructor the handleEndOrder

2
  • what do you mean onClick is not working Commented Apr 27, 2018 at 13:11
  • @ShubhamKhatri The functions it's not called when i click in button. Commented Apr 27, 2018 at 13:13

1 Answer 1

2

Since you haven't specified the type on button, it is by default submit, you need to either specify the type="button" or use e.preventDefault() like

<button class="btn btn-xs btn-danger pull-right" type="button" onClick={e => this.handleRemoveClick(material)}>x</button>

or

handleRemoveClick = (e, material) => {
  e.preventDefault();
  let idMaterial = material.material_id;
  if(this.state.operation === 0){
    this.setState( { previewShowAlertRemoveProduct : true })
    }
    this.setState( { operation : 1, material_id : idMaterial})
}
<button class="btn btn-xs btn-danger pull-right"  onClick={e => this.handleRemoveClick(e, material)}>x</button>
Sign up to request clarification or add additional context in comments.

2 Comments

So in case i want to call the handleEndOrder i only need define .bind in constructor and type button ?
Glad to have helped :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.