React Onmousedown: Passing Event Along With Parameters
I am trying to pass an event into an handleOnMouseDown function along with two other parameters. The code I have now looks like this: onMouseDown={(e) => {this.handleMouseDown(e
Solution 1:
Most of the event handlers only accept the event object as their parameter. But that doesn't mean you can't pass other things into the handleMouseDown
callback function. You'd want to write it like this:
handleMouseDown = (e, row, col) => {
e.persist()
e.preventDefault()
console.log(e, row, col)
// whatever you'd like to do with e, row, and col
}
// Inside your render:
const row = 'whatever'
const col = 'and stuff'
return (
<button onMouseDown={(e) => {this.handleMouseDown(e,row,col)}}>
This will work
</button>
)
Post a Comment for "React Onmousedown: Passing Event Along With Parameters"