react-use-intercom is a specialized React library that provides a hook-driven abstraction layer for integrating the Intercom chat widget into web applications. Currently at version 5.5.0, it maintains an active and agile release cadence, frequently publishing minor and patch updates to support new IntercomJS features, address bugs, and improve compatibility. Key differentiators include its adherence to modern React patterns by leveraging hooks, full TypeScript support for enhanced developer experience, a minimal bundle size with no external dependencies, and built-in safeguards designed to prevent common issues in Server-Side Rendering (SSR) environments like Next.js and Gatsby. It also allows for seamless integration with existing Intercom instances, such as those loaded via Segment. The library aims for a direct, one-to-one mapping of Intercom's vanilla JavaScript API methods to simplify usage while maintaining full access to Intercom's capabilities. Developers should note that many issues might stem from the underlying IntercomJS library itself.
npm install react-use-intercomVerified import paths — ran on the pinned version, not inferred.
This code demonstrates how to initialize Intercom using IntercomProvider, boot the messenger, and control its visibility using the useIntercom hook.
Refer to Intercom's documentation for required CSP directives and ensure your server-side rendering or build process correctly injects nonces into the Intercom script tags if used.
Place IntercomProvider high in your component tree and ensure any custom logic interacting with `window.Intercom` is wrapped in `typeof window !== 'undefined'` checks or executed in `useEffect` hooks.
Consult the official Intercom documentation and community forums (community.intercom.com) for issues related to Intercom's core behavior, API limits, or configuration rather than solely focusing on the React wrapper.
Ensure `IntercomProvider` is placed as high as possible in your React component hierarchy, above any components that call `useIntercom`.
Ensure code interacting with `window` is executed only in the browser context. `react-use-intercom` generally handles this, but custom logic may require `typeof window !== 'undefined'` checks or `useEffect` for client-side execution.
Wrap the component that uses `useIntercom` (and its ancestors) with `<IntercomProvider appId="YOUR_APP_ID">...</IntercomProvider>`.
Update your CSP to allow `script-src`, `style-src`, `connect-src`, and other necessary directives from Intercom's domains. For dynamic script injection, you might need to use a `nonce` attribute for scripts.
Verify that `IntercomProvider` is correctly initialized with an `appId` and that `useIntercom` is called within a functional component rendered under `IntercomProvider`. Ensure `IntercomProvider` has had time to initialize on the client side, especially in complex hydration scenarios.