From d9bd48b9a68de6c866114b3ffb0ec6f8e2a1518e Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 1 Jun 2022 10:21:44 +0100 Subject: [PATCH] Split out client sync listeber into separate useEffect --- src/room/usePTT.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/room/usePTT.ts b/src/room/usePTT.ts index 1a72faa..8a1f916 100644 --- a/src/room/usePTT.ts +++ b/src/room/usePTT.ts @@ -262,14 +262,10 @@ export const usePTT = ( window.addEventListener("keyup", onKeyUp); window.addEventListener("blur", onBlur); - client.on(ClientEvent.Sync, onClientSync); - return () => { window.removeEventListener("keydown", onKeyDown); window.removeEventListener("keyup", onKeyUp); window.removeEventListener("blur", onBlur); - - client.removeListener(ClientEvent.Sync, onClientSync); }; }, [ groupCall, @@ -285,6 +281,14 @@ export const usePTT = ( onClientSync, ]); + useEffect(() => { + client.on(ClientEvent.Sync, onClientSync); + + return () => { + client.removeListener(ClientEvent.Sync, onClientSync); + }; + }, [client, onClientSync]); + const setTalkOverEnabled = useCallback((talkOverEnabled) => { setState((prevState) => ({ ...prevState,