@@ -9,11 +9,13 @@ import { useMethod, useConversation, useUIBox, useMountBox } from "../hooks";
9
9
import { EventListeners } from "../EventListeners" ;
10
10
import { UIBoxProps } from "../types" ;
11
11
import { BoxContext } from "../MountedBox" ;
12
+ import { useEffect } from "react" ;
12
13
13
14
type PopupProps = UIBoxProps < Talk . Popup > &
14
15
Talk . PopupOptions & {
15
16
highlightedWords ?: Parameters < Talk . Popup [ "setHighlightedWords" ] > [ 0 ] ;
16
17
popupRef ?: React . MutableRefObject < Talk . Popup | undefined > ;
18
+ show ?: boolean ;
17
19
children ?: React . ReactNode ;
18
20
} ;
19
21
@@ -39,6 +41,7 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
39
41
conversationId,
40
42
syncConversation,
41
43
asGuest,
44
+ show,
42
45
popupRef,
43
46
children,
44
47
...optionsAndEvents
@@ -53,7 +56,20 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
53
56
useMethod ( box , presence , "setPresence" ) ;
54
57
useMethod ( box , highlightedWords , "setHighlightedWords" ) ;
55
58
useConversation ( session , box , syncConversation , conversationId , asGuest ) ;
56
- useMountBox ( box , undefined ) ;
59
+ const mounted = useMountBox ( box , { show : show ?? true } ) ;
60
+
61
+ useEffect ( ( ) => {
62
+ if ( show === undefined || ! mounted ) {
63
+ return ;
64
+ }
65
+
66
+ if ( show ) {
67
+ box ?. show ( ) ;
68
+ } else {
69
+ box ?. hide ( ) ;
70
+ }
71
+
72
+ } , [ show , mounted , box ] )
57
73
58
74
return (
59
75
< BoxContext . Provider value = { box } >
0 commit comments