I have a simple code:
kill = e => {
// do the killing
}
save = e => {
e.preventDefault()
console.info(e.currentTarget)
}
render(){
return <form onSubmit={this.save}>
<button key={new Date().getTime()} onDoubleClick={this.kill}>Delete</button>}
<button type="submit" key={new Date().getTime() + 100}>Save</button>
</form>
}
If I click the Delete Button, the form gets submitted -> I see it in the console.
Double click works, but prior to that the save() method is invoked.
I found this bug https://github.com/facebook/react/issues/8554, and tried adding the unique key to each button, but nothing changes.
What am I missing?
Try giving
type="button"to the button that you don't want to submit.Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button