How to pass Value to an Event Handler (React.js)
Context:
If you have a drop down menu and you want to call a function when a different option is selected (eg. slide 2), you can use the onChange attrbute.
If you then want to pass that option's value (eg. 2), you don't actually have to pass it as a parameter. The value is passed automatically in an object called event.
event is the object that has all the information about the event, ie. the user chose another option. event has a property called target, which returns the element that triggered the event.
In this case, target refers to the select tag, so event.target.value gives you the value that was chosen (eg.2)
Comments
Regards,
ReactJS Consult
Post a Comment