Skip to content

Commit 5c03565

Browse files
committed
refactor: ensure op stop when component unmount
1 parent 41c3403 commit 5c03565

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/typink/src/hooks/useWatchSystemEvents.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ export function useWatchSystemEvents(parameters: {
2828
() => {
2929
if (!client || !watch) return;
3030

31-
const unsub = subscribeSystemEvents(callback);
31+
let unmounted = false;
32+
33+
const unsub = subscribeSystemEvents((events) => {
34+
if (unmounted) {
35+
unsub && unsub();
36+
return;
37+
}
38+
39+
callback(events);
40+
});
3241

3342
return () => {
3443
unsub && unsub();
44+
unmounted = true;
3545
};
3646
},
3747
useDeepDeps([client, callback, watch]),

0 commit comments

Comments
 (0)