Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use react devtools to get function tied to an onClick event listener

I want to use react devtools to see the source code of an onClick function on a website, specifically, wanderu.com

Please note I am new to react devtools and do not possess yet a good understanding of how this works. I've spent about 2 hours trying to figure this out

On the site in between the destination fields there is an image tag that when clicked, it changes the order of the destinations:

enter image description here

I want to use react devtools to find the code to see how this works.

When I open this in the react dev tools, I can see the following:

enter image description here

When I expand the onClick tab, it doesn't show me anything.

enter image description here

Why? How come in this tab I cannot see the function that onClick is tied to?

When I step back and look at the component, I can see the props of the component that contains this feature:

enter image description here

enter image description here

But I don't see how or where to find the function that is responsible for switching the two input fields.

Google search of "get onclick function react devtools" and relevant keywords doesn't give helpful results in regards to see a function tied to an eventlistener in context of react, just vanilla JS.

In context of React and React devtools, how do you see a function that is tied to an event listener?

like image 880
kawnah Avatar asked Mar 03 '23 16:03

kawnah


1 Answers

One way to begin this task is to set an event breakpoint.

Go into the "Sources" tab in devtools, expand "Event Listener Breakpoints", find and expand "Mouse" and select "click". This will cause the code on that page to pause execution and you can inspect the code involved.

I tried this out on the website you provided and found the code to be minified/obfuscated which as you can expect, makes debugging and reverse engineering difficult, but not impossible.

demonstration

like image 57
Peter Avatar answered Apr 06 '23 00:04

Peter