mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
fix(react/dialogs): listener leak in modal
This commit is contained in:
parent
cb650b70cb
commit
83fb62d4df
@ -28,14 +28,23 @@ export default function Modal({ children, className, size, title, footer, onShow
|
|||||||
if (onShown || onHidden) {
|
if (onShown || onHidden) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const modalElement = modalRef.current;
|
const modalElement = modalRef.current;
|
||||||
if (modalElement) {
|
if (!modalElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (onShown) {
|
if (onShown) {
|
||||||
modalElement.addEventListener("shown.bs.modal", onShown);
|
modalElement.addEventListener("shown.bs.modal", onShown);
|
||||||
}
|
}
|
||||||
if (onHidden) {
|
if (onHidden) {
|
||||||
modalElement.addEventListener("hidden.bs.modal", onHidden);
|
modalElement.addEventListener("hidden.bs.modal", onHidden);
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
|
if (onShown) {
|
||||||
|
modalElement.removeEventListener("shown.bs.modal", onShown);
|
||||||
}
|
}
|
||||||
|
if (onHidden) {
|
||||||
|
modalElement.removeEventListener("hidden.bs.modal", onHidden);
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user