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 */