why react set onClick callback three arguments?
nativeEvent can get by proxyEvent.nativeEvent. Why React set nativeEvent at the third argument.
If I click the button, console.log(args) give me Proxy, undefined, Event, the third argument is not what i want.
but in componentDidMount, call this.clickHandler, it give me null, null, 'b2c', the third argument 'b2c' that's what i want.
class ReactEventArgument extends React.Component{
componentDidMount() {
this.clickHandler(null, null, 'b2c');
}
render() {
return <div>
<Child clickHandler={this.clickHandler}></Child>
</div>
}
clickHandler = (e, v, type = 'b2c') => {
console.log(Array.prototype.slice.call(arguments));
console.log(e, v, type);
//if I click the button, I get a wrong type, type is nativeEvent, not my argument.
}
}
class Child extends React.Component{
render() {
const {clickHandler} = this.props;
return <div>
<button type="button" onClick={clickHandler}>click me</button>
</div>
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
I have to change the button like this:
<button type="button" onClick={e => clickHandler(e, null, undefined)}>click me too</button>