0

Don't want to call a certain function on specific conditions

I am using react js, I am calling a function (handleRowClick) onClick on table row but there is a "copy to clipboard" button as well in the row. I don't want (handleRowClick) to be called when "copy to clipboard" button is clicked. Any ideas on how can i achieve that?

9th Aug 2022, 12:55 PM
Ashutosh Raturi
Ashutosh Raturi - avatar
3 Answers
0
You can call the stopPropagation() method on the event in the function that handles the "copy to clipboard". For example: const handleCopyToClipboard = (e)=>{ e.stopPropagation(); //function body }
9th Aug 2022, 2:07 PM
Baribor Saturday
Baribor Saturday - avatar
0
Baribor Saturday There is no explicit function for copy to clipboard. I am using a utility component for that <CopyToClipboard text={...} />
9th Aug 2022, 2:16 PM
Ashutosh Raturi
Ashutosh Raturi - avatar
0
Ashutosh Raturi okay. Try wrapping the CopyToClipboard component in a div, then add a click listener to the div that will stop the propagation
9th Aug 2022, 2:23 PM
Baribor Saturday
Baribor Saturday - avatar