From ad183650160091a3e976c2cea3d809eb9649d982 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 31 Oct 2025 15:13:14 +0100 Subject: [PATCH] Add callback to memorize leave function. --- packages/react/src/hooks/use-echo.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react/src/hooks/use-echo.ts b/packages/react/src/hooks/use-echo.ts index 2697aa9e..0ab2a268 100644 --- a/packages/react/src/hooks/use-echo.ts +++ b/packages/react/src/hooks/use-echo.ts @@ -127,6 +127,10 @@ export const useEcho = < leaveChannel(channel, leaveAll); }, dependencies); + const leave = useCallback(() => { + tearDown(true); + }, dependencies); + useEffect(() => { if (initialized.current) { subscription.current = resolveChannelSubscription(channel); @@ -147,7 +151,7 @@ export const useEcho = < /** * Leave the channel and also its associated private and presence channels */ - leave: () => tearDown(true), + leave, /** * Stop listening for event(s) without leaving the channel */