Andarist / Andarist/use-onclickoutside
Add `capture` option for event handler?
- Lenguaje dominante
- TypeScript
- Estrellas
- 496
- Forks
- 27
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I faced the problem of inconsistent event handling. It appears in my SPA, when I navigate from route with component with dropdown that uses `useOnClickOutside` hook, and then navigate back. Component is being totally unmount during navigation.
When it is mounted back, `useOnClickOutside` adds event listener document again. I click on dropdown-list option, state of component changes, then list completely rerendered. And _somehow_ `mousedown` event for dropdown option fired before `mousedown` event on document. Between these to events dom node is being removed, so `onClickOutside` triggered.
I tried to provide `{ capture: true }` to `mousedown` event listener for document and now it's ok. So I think `capture` option should be provided by default, or at least via optional argument to hook. Is there any downside of this solution?
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.