react: Strange second argument passed to event handler (always undefined)
I’ve found a bug.
I’ve attached event listener with onClick property like this:
<a href="#" onClick={function (event) {
console.log(arguments.length); // prints 2
// arguments[0] = SyntheticEvent - it's ok
// arguments[1] = undefined - what is this???
}}>Click me</a>
The event listener called with 2 arguments: synthetic event and strange undefined value.
I think, normal behavior is when handler called with a single param - event object.
Windows 10. Chrome 53. React version - 15.2.0.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 31 (10 by maintainers)
Yes, it is. I’ve implemented custom basic component:
And got a problem with my
eventHandlermethod. This method allows to attach event handlers defined in component classes with some extra data binding, but always with first argument is event object:I think the only argument that’s part of the React contract is the event. If you see other arguments there it’s a bug. That said if you get these arguments from a third party library, that library could be adding arguments.
Totally understandable, the codebase can be dense sometimes. But if you wanted to give it a try I would be happy to work with you on your PR! Otherwise one of us will try and get to it when we can 👍
I’m going to close this issue out because I think we’ve identified what those additional arguments are? You should expect to see at least
SyntheticEvent(orProxy) andEvent(the native event the browser is passing in, once the changes is master are released.