diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index f713f4b094..3de857af56 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -107,7 +107,9 @@ export default function App() { waku.relay.addObserver(handleRelayMessage, [ChatContentTopic]); - return; + return function cleanUp() { + waku?.relay.deleteObserver(handleRelayMessage, [ChatContentTopic]); + }; }, [waku]); useEffect(() => { @@ -140,8 +142,7 @@ export default function App() { handleProtocolChange.bind({}, waku) ); - // To clean up listener when component unmounts - return () => { + return function cleanUp() { waku?.libp2p.peerStore.removeListener( 'change:protocols', handleProtocolChange.bind({}, waku)