uidotdev / usehooks

A collection of modern, server-safe React hooks – from the ui.dev team
https://usehooks.com
MIT License
9.26k stars 496 forks source link

Can't stop propagation with useClickAway #249

Open kttmv opened 11 months ago

kttmv commented 11 months ago

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())
})
tylermcginnis commented 10 months ago

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

kttmv commented 10 months ago

Here's the replication

KevinArce98 commented 6 months ago

is there any solution for this issue?