Monday, September 17, 2018

React JS send custom parameter to onClick

If you need to send a custom parameter to your onClick event handler, do like this

<a href="" onClick={()=> {this.tabClicked("Exceptions")}}>Exceptions</a>

if you need to pass the event as well to the onClick handler use like this

<a href="" onClick={(evt)=> {this.tabClicked(evt,"Exceptions")}}>Exceptions</a>


and in your tabClicked() you can get the parameters like this

tabClicked(evt, tab) {
evt.preventDefault(); // Let's stop this event.
alert(tab); // should alert Exceptions
}

No comments:

Get Indian financial year based on date

This function lets you get the start and end date of Indian financial year based on given date. This can also be modified for US financia...