Skip to content

Commit a657d43

Browse files
committed
chore: add disconnect on unmount chat context
1 parent 2593501 commit a657d43

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/uikit-react-native/src/containers/SendbirdUIKitContainer.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,11 @@ const SendbirdUIKitContainer = ({
169169
}
170170

171171
return () => {
172-
if (!isFirstMount) {
173-
unsubscribes.current.forEach((u) => {
174-
try {
175-
u();
176-
} catch {}
177-
});
178-
}
172+
unsubscribes.current.forEach((u) => {
173+
try {
174+
u();
175+
} catch {}
176+
});
179177
};
180178
}, [appId, internalStorage]);
181179

packages/uikit-react-native/src/contexts/SendbirdChatCtx.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useState } from 'react';
1+
import React, { useCallback, useEffect, useState } from 'react';
22

33
import { useAppFeatures } from '@sendbird/uikit-chat-hooks';
44
import { SBUConfig, useUIKitConfig } from '@sendbird/uikit-tools';
@@ -144,6 +144,12 @@ export const SendbirdChatProvider = ({
144144
else if (status === 'background') sdkInstance.connectionState === 'OPEN' && sdkInstance.setBackgroundState();
145145
});
146146

147+
useEffect(() => {
148+
return () => {
149+
sdkInstance.disconnect().then(() => _setCurrentUser(undefined));
150+
};
151+
}, [sdkInstance]);
152+
147153
const value: SendbirdChatContextType = {
148154
sdk: sdkInstance,
149155
emojiManager,

0 commit comments

Comments
 (0)