Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devrnt committed Feb 18, 2024
1 parent 5b74e8a commit 6361d10
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions packages/react-use-intercom/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand Down

0 comments on commit 6361d10

Please sign in to comment.