Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-use-intercom

> 前端框架
Open source

☎️ React Intercom integration without the hassle, powered by hooks.

377 stars0 likes0 views
WebsiteGitHub

About

☎️ React Intercom integration without the hassle, powered by hooks.

react-use-intercom

A React Intercom integration powered by hooks.

Features

  • Hooks
  • Written in TypeScript
  • Documented, self explaining methods
  • Tiny size without any external libraries
  • Safeguard for SSR environments (NextJS, Gatsby)
  • Compatible to hook into existing Intercom instance (loaded by Segment)

Installation

bash
# pnpm
pnpm add react-use-intercom

# npm
npm install react-use-intercom

# yarn
yarn add react-use-intercom

Quickstart

typescript
import * as React from 'react';

import { IntercomProvider, useIntercom } from 'react-use-intercom';

const INTERCOM_APP_ID = 'your-intercom-app-id';

const App = () => (
  
    
  
);

// Anywhere in your app
const HomePage = () => {
  const { boot, shutdown, hide, show, update } = useIntercom();

  return Boot intercom! ☎️;
};

Context

This library is a React abstraction of IntercomJS. react-use-intercom tries to keep as close as a one-on-one abstraction of the "vanilla" Intercom functionality.

Note that many issues could be related to the vanilla IntercomJS library. Please see https://community.intercom.com/ before reporting an issue here.

Links

  • API
  • Playground
  • Examples
  • TypeScript
  • Troubleshoot
  • Advanced

API

  • IntercomProvider
  • useIntercom
  • IntercomProps

IntercomProvider

IntercomProvider is used to initialize the window.Intercom instance. It makes sure the initialization is only done once. If any listeners are passed, the IntercomProvider will make sure these are attached.

Place the IntercomProvider as high as possible in your application. This will make sure you can call useIntercom anywhere.

Props

name type description required default
appId string app ID of your Intercom instance true
children React.ReactNode React children true
autoBoot boolean indicates if Intercom should be automatically booted. If true no need to call boot, the IntercomProvider will call it for you false false
onHide () => void triggered when the Messenger hides false
onShow () => void triggered when the Messenger shows false
onUnreadCountChange (number) => void triggered when the current number of unread messages changes false
onUserEmailSupplied () => void triggered when a visitor enters their email into the Messenger false
shouldInitialize boolean indicates if the Intercom should be initialized. Can be used in multistaged environment false true
apiBase string If you need to route your Messenger requests through a different endpoint than the default. Generally speaking, this is not needed.
Format: https://${INTERCOM_APP_ID}.intercom-messenger.com (See: https://github.com/devrnt/react-use-intercom/pull/96) false
initializeDelay number Indicates if the intercom initialization should be delayed, delay is in ms, defaults to 0. See https://github.com/devrnt/react-use-intercom/pull/236 false
autoBootProps IntercomProps Pass properties to boot method when autoBoot is true false
crossOrigin 'anonymous' | 'use-credentials' | '' Sets the crossOrigin attribute on the Messenger `` (standard DOM attribute, not an Intercom API). Use 'anonymous' for full error details in error logging; works because Intercom's CDN allows CORS false
onLoad () => void triggered when the Messenger script has loaded successfully false
onLoadFailed () => void triggered when the Messenger script has failed to load (network issues, Intercom downtime, firewall, blocking browser extensions, ...) false

Example

typescript
const App = () => {
  const [unreadMessagesCount, setUnreadMessagesCount] = React.useState(0);

  const onHide = () => console.log('Intercom did hide the Messenger');
  const onShow = () => console.log('Intercom did show the Messenger');
  const onUnreadCountChange = (amount: number) => {
    console.log('Intercom has a new unread message');
    setUnreadMessagesCount(amount);
  };
  const onUserEmailSupplied = () => {
    console.log('Visitor has entered email');
  };

  return (
    
      
Hi there, I am a child of the IntercomProvider

    
  );
};

useIntercom

Used to retrieve all methods bundled with Intercom. These are based on the official Intercom docs. Some extra methods were added to improve convenience.

Make sure IntercomProvider is wrapped around your component when calling useIntercom().

Remark - You can't use useIntercom() in the same component where IntercomProvider is initialized.

API

name type description
isOpen boolean the visibility status of the messenger
boot (props?: IntercomProps) => void boots the Intercom instance, not needed if autoBoot in IntercomProvider is true
shutdown () => void shuts down the Intercom instance
hardShutdown () => void same functionality as shutdown, but makes sure the Intercom cookies, window.Intercom and window.intercomSettings are removed.
update (props?: IntercomProps) => void updates the Intercom instance with the supplied props. To initiate a 'ping', call update without props
hide () => void hides the Messenger, will call onHide if supplied to IntercomProvider
show () => void shows the Messenger, will call onShow if supplied to IntercomProvider
showMessages () => void shows the Messenger with the message list
showNewMessage (content?: string) => void shows the Messenger as if a new conversation was just created. If content is passed, it will fill in the message composer
startConversation (message: string) => void opens the Messenger and immediately starts a new conversation with the supplied message
getVisitorId () => string gets the visitor id
startTour (tourId: number) => void starts a tour based on the tourId
startChecklist (checklistId: number) => void starts a checklist based on the checklistId
trackEvent (event: string, metaData?: object) => void submits an event with optional metaData
showArticle (articleId: string) => void opens the Messenger with the specified article by articleId
startSurvey (surveyId: number) => void Trigger a survey in the Messenger by surveyId
showSpace (spaceName: IntercomSpace) => void Opens the Messenger with the specified space
showNews (newsId: number) => void Opens the Messenger with the specified news item by newsId
showTicket (ticketId: number) => void Opens the Messenger with the specified ticket by ticketId
showConversation (conversationId: number) => void Opens the Messenger with the specified conversation by conversationId
hideNotifications (hidden: boolean) => void controls the visibility of in-app notifications, pass true to hide or false to show them
setAuthTokens (authTokens: AuthTokens) => void sets/refreshes the per-user Data Connector auth tokens at runtime without a full update

Example

…

IntercomProps

All the Intercom default attributes/props are camel cased (appId instead of app_id) in react-use-intercom, see IntercomProps to see what attributes you can pass to boot or update. Or check the Intercom docs to see all the available attributes/props.

Remark - all the listed Intercom attributes here are snake cased, in react-use-intercom these are camel cased.

Custom attributes

Still want to pass custom attributes to Intercom? Whether boot or update is used, you can add your custom properties by passing these through customAttributes in the boot or update method.

Remark - the keys of the customAttributes object should be snake cased (this is how Intercom wants them). They are rawly passed to Intercom.

typescript
const { boot } = useIntercom();

boot({ 
 name: 'Russo',
 customAttributes: { custom_attribute_key: 'hi there' },
})

Authentication tokens

For secure data operations, you can pass authentication tokens to Intercom using the authTokens property. This accepts an object with any string key-value pairs.

typescript
const { boot } = useIntercom();

boot({
 email: '[email protected]',
 userId: '9876',
 authTokens: {
   security_token: 'abc...', // JWT token
   api_token: 'xyz...',
   // Any other tokens as key-value pairs
 }
})

This is distinct from intercomUserJwt, which is for Messenger identity verification. To refresh a token during a session without sending a full update, use the setAuthTokens method:

typescript
const { setAuthTokens } = useIntercom();

setAuthTokens({ security_token: 'refreshed-jwt' });

Playground

Small playground to showcase the functionalities of react-use-intercom.

useIntercom

[https://devrnt.githu

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptgatsbyhooksintercomintercom-react

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架