Skip to content

Commit 3c0d3de

Browse files
Merge pull request #464 from AntonGreger/agr/memorize-leave-function
Add callback to memorize leave function.
2 parents c4c3200 + ad18365 commit 3c0d3de

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/react/src/hooks/use-echo.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ export const useEcho = <
127127
leaveChannel(channel, leaveAll);
128128
}, dependencies);
129129

130+
const leave = useCallback(() => {
131+
tearDown(true);
132+
}, dependencies);
133+
130134
useEffect(() => {
131135
if (initialized.current) {
132136
subscription.current = resolveChannelSubscription<TDriver>(channel);
@@ -147,7 +151,7 @@ export const useEcho = <
147151
/**
148152
* Leave the channel and also its associated private and presence channels
149153
*/
150-
leave: () => tearDown(true),
154+
leave,
151155
/**
152156
* Stop listening for event(s) without leaving the channel
153157
*/

0 commit comments

Comments
 (0)