File tree 2 files changed +16
-3
lines changed
2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
- import { useLayoutEffect } from 'react' ;
1
+ import { DependencyList , useLayoutEffect } from 'react' ;
2
2
3
3
// this hook accepts a callback to run component is unmounted
4
- export function useUnmount ( callback : ( ) => void ) {
4
+ export function useUnmount ( callback : ( ) => void , deps : DependencyList = [ ] ) {
5
5
useLayoutEffect ( ( ) => {
6
6
return ( ) => {
7
7
callback ( ) ;
8
8
} ;
9
- } , [ ] ) ;
9
+ } , deps ) ;
10
10
}
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ import { useMarkAsReadScheduler } from './hooks/useMarkAsReadScheduler';
31
31
import { ConfigureSessionTypes } from './hooks/useConnect/types' ;
32
32
import { useMarkAsDeliveredScheduler } from './hooks/useMarkAsDeliveredScheduler' ;
33
33
import { getCaseResolvedReplyType , getCaseResolvedThreadReplySelectType } from './utils/resolvedReplyType' ;
34
+ import { useUnmount } from '../hooks/useUnmount' ;
35
+ import { disconnectSdk } from './hooks/useConnect/disconnectSdk' ;
34
36
35
37
export type UserListQueryType = {
36
38
hasNext ?: boolean ;
@@ -192,6 +194,17 @@ const SendbirdSDK = ({
192
194
initDashboardConfigs,
193
195
} ) ;
194
196
197
+ useUnmount ( ( ) => {
198
+ if ( typeof sdk . disconnect === 'function' ) {
199
+ disconnectSdk ( {
200
+ logger,
201
+ sdkDispatcher,
202
+ userDispatcher,
203
+ sdk,
204
+ } ) ;
205
+ }
206
+ } , [ sdk . disconnect ] ) ;
207
+
195
208
// to create a pubsub to communicate between parent and child
196
209
useEffect ( ( ) => {
197
210
setLogger ( LoggerFactory ( logLevel as LogLevel ) ) ;
You can’t perform that action at this time.
0 commit comments