uidotdev / usehooks

A collection of modern, server-safe React hooks – from the ui.dev team

Home Page:https://usehooks.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't stop propagation with useClickAway

kttmv opened this issue · 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())
})

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