Skip to content

Commit

Permalink
fix(core): Cleanup spotlight event target listeners (#104)
Browse files Browse the repository at this point in the history
* fix(core): Cleanup spotlight event target listeners

* changeset
  • Loading branch information
Lms24 authored Nov 22, 2023
1 parent 72ca15e commit 76721fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-carrots-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/core': patch
---

fix(core): Use effect and cleanup spotlight event target listeners
22 changes: 16 additions & 6 deletions packages/core/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ export default function App({
};
}, [integrations, sidecar]);

eventTarget.addEventListener('open', () => {
setOpen(true);
});
useEffect(() => {
const onOpen = () => {
setOpen(true);
};

const onClose = () => {
setOpen(false);
};

eventTarget.addEventListener('close', () => {
setOpen(false);
});
eventTarget.addEventListener('open', onOpen);
eventTarget.addEventListener('close', onClose);

return () => {
eventTarget.removeEventListener('open', onOpen);
eventTarget.removeEventListener('close', onClose);
};
}, [eventTarget]);

useEffect(() => {
if (!isOpen) {
Expand Down

0 comments on commit 76721fd

Please sign in to comment.