Skip to content
Advertisement

How to handle two functions onClick

In my Class component App.jsx I have the following function:

JavaScript

Which is being handled at render() when I click on a subcomponent inside a <div>, like so:

JavaScript

On its turn, Position.jsx handles onClick():

JavaScript

But now I’d like to handle a second function when <div> is clicked, say:

JavaScript

which I would pass, on its own, like so:

JavaScript

How do I handle BOTH functions onClick() at once in

JavaScript

?

Advertisement

Answer

Just like you can invoke multiple functions at once in a JS listener with

JavaScript

You can do the same thing in React by defining the onClick to be a function which invokes both:

JavaScript
JavaScript
Advertisement