Skip to content

Commit ecc919c

Browse files
committed
cleanup queue on unmount
1 parent c7095a7 commit ecc919c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

components/use-live-comments.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export default function useLiveComments (rootId, after, sort) {
3737
setLatest(prevLatest => getLatestCommentCreatedAt(data.newComments.comments, prevLatest))
3838
console.log('latest', latest)
3939
}, [data, client, rootId, sort])
40+
41+
// cleanup queue on unmount to prevent memory leaks
42+
useEffect(() => {
43+
return () => {
44+
queue.current = []
45+
}
46+
}, [])
4047
}
4148

4249
// the item query is used to update the item's newComments field

0 commit comments

Comments
 (0)