File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 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' ;
22
33// this hook accepts a callback to run component is unmounted
4- export function useUnmount ( callback : ( ) => void ) {
4+ export function useUnmount ( callback : ( ) => void , deps : DependencyList = [ ] ) {
55 useLayoutEffect ( ( ) => {
66 return ( ) => {
77 callback ( ) ;
88 } ;
9- } , [ ] ) ;
9+ } , deps ) ;
1010}
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ import { useMarkAsReadScheduler } from './hooks/useMarkAsReadScheduler';
3131import { ConfigureSessionTypes } from './hooks/useConnect/types' ;
3232import { useMarkAsDeliveredScheduler } from './hooks/useMarkAsDeliveredScheduler' ;
3333import { getCaseResolvedReplyType , getCaseResolvedThreadReplySelectType } from './utils/resolvedReplyType' ;
34+ import { useUnmount } from '../hooks/useUnmount' ;
35+ import { disconnectSdk } from './hooks/useConnect/disconnectSdk' ;
3436
3537export type UserListQueryType = {
3638 hasNext ?: boolean ;
@@ -192,6 +194,17 @@ const SendbirdSDK = ({
192194 initDashboardConfigs,
193195 } ) ;
194196
197+ useUnmount ( ( ) => {
198+ if ( typeof sdk . disconnect === 'function' ) {
199+ disconnectSdk ( {
200+ logger,
201+ sdkDispatcher,
202+ userDispatcher,
203+ sdk,
204+ } ) ;
205+ }
206+ } , [ sdk . disconnect ] ) ;
207+
195208 // to create a pubsub to communicate between parent and child
196209 useEffect ( ( ) => {
197210 setLogger ( LoggerFactory ( logLevel as LogLevel ) ) ;
You can’t perform that action at this time.
0 commit comments