I am getting the below error while binding the values to the function.
TypeError: Cannot read property 'bind' of undefined
Please see the code below:
<button className={classes.ButtonStyle} onClick={props.onClickHandler.bind(null,props.id)}>{props.children}</button>
But the arrow function notation is working fine though:
onClick={(e)=>{props.onClickHandler(props.id,e)}}
May I please know where I have done wrong? Also I am not using class based components but only functional based components(hooks).
The onClickHandler function is as below:
const onClickHandler = (id, e) =>{
e.preventDefault();
console.log('buttonSetNullHandler', id);
}
bindhere, ??onClick={()=> props.onClickHandler(props.id) }this should definitely do the job. why over cooking