From 6361d10b1903673bc6f0d2f90329f5029e4ca2df Mon Sep 17 00:00:00 2001 From: Jonas De Vrient <32844711+devrnt@users.noreply.github.com> Date: Sun, 18 Feb 2024 09:54:12 +0000 Subject: [PATCH] wip --- packages/react-use-intercom/src/provider.tsx | 39 +++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/react-use-intercom/src/provider.tsx b/packages/react-use-intercom/src/provider.tsx index 79bb9c9..48d087e 100644 --- a/packages/react-use-intercom/src/provider.tsx +++ b/packages/react-use-intercom/src/provider.tsx @@ -83,23 +83,36 @@ export const IntercomProvider: React.FC< if (onShow) onShow(); }, [onShow, setIsOpen]); - if (!isSSR && shouldInitialize && !isInitialized.current) { - initialize(appId, initializeDelay); + React.useEffect(() => { + if (!isSSR && shouldInitialize && !isInitialized.current) { + initialize(appId, initializeDelay); - // attach listeners - IntercomAPI('onHide', onHideWrapper); - IntercomAPI('onShow', onShowWrapper); - IntercomAPI('onUserEmailSupplied', onUserEmailSupplied); + // attach listeners + IntercomAPI('onHide', onHideWrapper); + IntercomAPI('onShow', onShowWrapper); + IntercomAPI('onUserEmailSupplied', onUserEmailSupplied); - if (onUnreadCountChange) - IntercomAPI('onUnreadCountChange', onUnreadCountChange); + if (onUnreadCountChange) + IntercomAPI('onUnreadCountChange', onUnreadCountChange); - if (autoBoot) { - boot(autoBootProps); - } + if (autoBoot) { + boot(autoBootProps); + } - isInitialized.current = true; - } + isInitialized.current = true; + } + }, [ + appId, + shouldInitialize, + autoBoot, + autoBootProps, + boot, + initializeDelay, + onHideWrapper, + onShowWrapper, + onUserEmailSupplied, + onUnreadCountChange, + ]); const ensureIntercom = React.useCallback( (functionName: string, callback: (() => void) | (() => string)) => {