File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,7 +115,12 @@ Used to retrieve all methods bundled with Intercom. These are based on the offic
115115
116116 Make sure ` IntercomProvider ` is wrapped around your component when calling ` useIntercom() ` .
117117
118- ** Remark** - You can't use ` useIntercom() ` in the same component where ` IntercomProvider ` is initialized.
118+ ** Remark** - You can't use ` useIntercom() ` in the same component where ` IntercomProvider ` is initialized.
119+
120+ #### State
121+ | name | type | description |
122+ | ---------------------| ------------------| -----------------------------------------------------------------------------------------|
123+ | isOpen | boolean | the visibility status of the messenger |
119124
120125#### Methods
121126| name | type | description |
Original file line number Diff line number Diff line change @@ -75,12 +75,24 @@ export const IntercomProvider: React.FC<React.PropsWithChildren<
7575 [ apiBase , appId , shouldInitialize ] ,
7676 ) ;
7777
78+ const [ isOpen , setIsOpen ] = React . useState ( false ) ;
79+
80+ const onHideWrapper = React . useCallback ( ( ) => {
81+ setIsOpen ( false ) ;
82+ if ( onHide ) onHide ( ) ;
83+ } , [ onHide , setIsOpen ] ) ;
84+
85+ const onShowWrapper = React . useCallback ( ( ) => {
86+ setIsOpen ( true ) ;
87+ if ( onShow ) onShow ( ) ;
88+ } , [ onShow , setIsOpen ] ) ;
89+
7890 if ( ! isSSR && shouldInitialize && ! isInitialized . current ) {
7991 initialize ( appId , initializeDelay ) ;
8092
8193 // attach listeners
82- if ( onHide ) IntercomAPI ( 'onHide' , onHide ) ;
83- if ( onShow ) IntercomAPI ( 'onShow' , onShow ) ;
94+ IntercomAPI ( 'onHide' , onHideWrapper ) ;
95+ IntercomAPI ( 'onShow' , onShowWrapper ) ;
8496 if ( onUnreadCountChange )
8597 IntercomAPI ( 'onUnreadCountChange' , onUnreadCountChange ) ;
8698
@@ -231,6 +243,7 @@ export const IntercomProvider: React.FC<React.PropsWithChildren<
231243 update,
232244 hide,
233245 show,
246+ isOpen,
234247 showMessages,
235248 showNewMessages,
236249 getVisitorId,
@@ -245,6 +258,7 @@ export const IntercomProvider: React.FC<React.PropsWithChildren<
245258 update ,
246259 hide ,
247260 show ,
261+ isOpen ,
248262 showMessages ,
249263 showNewMessages ,
250264 getVisitorId ,
Original file line number Diff line number Diff line change @@ -314,6 +314,10 @@ export type IntercomContextValues = {
314314 * @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#section-intercomshow }
315315 */
316316 show : ( ) => void ;
317+ /**
318+ * The visibility status of the messenger.
319+ */
320+ isOpen : boolean ;
317321 /**
318322 * Opens the Messenger with the message list.
319323 */
You can’t perform that action at this time.
0 commit comments