I have a nested div in react like this:
<div onClick={() => fn_01()}>
<div onClick={() => fn_02()}>
</div>
</div>
I want to call different function when user click those div. But when I click the 1st div it called fn_01() and when I click the 2nd div it also call fn_01(). How can I solve this issue.
I am using functional component in my react project. I also implement Class component and call those method using this., which doesn't work also. I need this work in Functional Component
stopPropagtionbut it didn't work. ItIt does work, if you do it properly. Part of the problem with your code is that you're creating a wrapper function:onClick={() => fn_02()}. Instead, just passfn_02directly as the click handler:onClick={fn_02}. Then, declare theeventparameter infn_02:function fn_02(event)and in the body of the function callevent.stopPropagation(). (If you wanted to keep the wrapper, you'd need to pass theevent:onClick={(event) => fn_02(event)}.)