usehooks icon indicating copy to clipboard operation
usehooks copied to clipboard

Can't stop propagation with useClickAway

Open kttmv opened this issue 1 year ago • 3 comments

I have a SideMenu component, that should be closed when clicking outside of it, and a NavBar component with a button that toggles the SideMenu. When the SideMenu is open and I click the toggle button, two actions are dispatched: sideMenuClosed and sideMenuToggled. Basically, the SideMenu first closes and then immediately re-opens.

I've tried doing this, but it didn't help:

const ref = useClickAway((e) => {
    e.stopPropagation()
    e.stopImmediatePropagation()
    dispatch(sideMenuClosed())
})

kttmv avatar Oct 19 '23 21:10 kttmv

Any chance you can make a simple replication of it for me with Codesandbox?

tylermcginnis avatar Oct 23 '23 22:10 tylermcginnis

Here's the replication

kttmv avatar Oct 24 '23 07:10 kttmv

is there any solution for this issue?

KevinArce98 avatar Mar 10 '24 21:03 KevinArce98