Framework · Developer setup

AI live chat for React and Next.js, in one component

<ReplyzeChat /> puts the Replyze chat on your site: a launcher, an AI agent that answers from your knowledge base and hands over to your team, and live chat with your team. The useReplyze() hook lets your own buttons open it.

Card required · Cancel before day 15 and pay nothing

Replyze/react-live-chat on GitHub

Last reviewed 2026-11-13

Replyze on React and Next.js

4 steps · Developer setup

  1. 1Copy your widget token (wgt_...) from Settings → Integrations → Install widget in your Replyze dashboard.
  2. 2Install the package from GitHub: npm install github:Replyze/react-live-chat
  3. 3Render <ReplyzeChat token="wgt_YOUR_TOKEN" /> once, near the root of your app. In Next.js that is app/layout.tsx (App Router) or pages/_app.tsx (Pages Router).
  4. 4Deploy and open your site. Once the page has loaded, the chat launcher appears in the bottom corner.
Install
npm install github:Replyze/react-live-chat

Why Replyze for React and Next.js

  • One component, rendered once near the root. It renders nothing itself, so it doesn't change your markup or hydration, and it stays mounted while people move between pages.

  • Works with the Next.js App Router (Next.js 13.4 and newer) and Pages Router, Vite and other React 18 or 19 setups. app/layout.tsx can stay a server component.

  • useReplyze() gives your own buttons open(), close() and toggle() and the unread count. It needs no provider, and calls made before the widget has loaded wait and run once it starts.

  • Typed events (open, close, unread, message:sent, message:received, identified) and TypeScript types for every prop and method.

  • Identity verification built in: createUserHash() from @replyze/react/server signs a signed-in user on your server, so they become one verified contact in your inbox.

Install

Add Replyze to React and Next.js

Install the Replyze React package and render <ReplyzeChat /> once, near the root of your app. For the Next.js App Router and Pages Router, Vite and other React 18 or 19 apps.

  1. 1

    Copy your widget token (wgt_...) from Settings → Integrations → Install widget in your Replyze dashboard.

  2. 2

    Install the package from GitHub: npm install github:Replyze/react-live-chat

  3. 3

    Render <ReplyzeChat token="wgt_YOUR_TOKEN" /> once, near the root of your app. In Next.js that is app/layout.tsx (App Router) or pages/_app.tsx (Pages Router).

  4. 4

    Deploy and open your site. Once the page has loaded, the chat launcher appears in the bottom corner.

Install @replyze/react

npm install github:Replyze/react-live-chat

@replyze/react isn't on the npm registry yet, so this installs it from GitHub. npm builds it while it installs, so you need git.

Render <ReplyzeChat /> once, near the root of your app

import { ReplyzeChat } from '@replyze/react';

export default function App() {
  return (
    <>
      <YourApp />
      <ReplyzeChat token="wgt_YOUR_TOKEN" />
    </>
  );
}

Replace wgt_YOUR_TOKEN with your widget token from Settings → Integrations → Install widget in your Replyze dashboard.

Replyze/react-live-chatThe full README: props, events, identity verification, examples

Next.js: App Router and Pages Router

app/layout.tsx can stay a server component. <ReplyzeChat /> is already a client component: the package's entry starts with "use client". Keep the token in an environment variable, such as NEXT_PUBLIC_REPLYZE_TOKEN in .env.local.

In the Pages Router, render it in pages/_app.tsx instead. Components that use useReplyze() need 'use client' at the top, like any component with hooks.

app/layout.tsx
import type { ReactNode } from 'react';
import { ReplyzeChat } from '@replyze/react';

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <ReplyzeChat token={process.env.NEXT_PUBLIC_REPLYZE_TOKEN!} />
      </body>
    </html>
  );
}
.env.local
# .env.local
NEXT_PUBLIC_REPLYZE_TOKEN=wgt_YOUR_TOKEN
pages/_app.tsx (Pages Router)
import type { AppProps } from 'next/app';
import { ReplyzeChat } from '@replyze/react';

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Component {...pageProps} />
      <ReplyzeChat token={process.env.NEXT_PUBLIC_REPLYZE_TOKEN!} />
    </>
  );
}

Your own chat button

useReplyze() returns the chat's state (status, isOpen, unreadCount) and the widget's methods, so any button can open the chat and show the unread count.

useReplyze() needs no provider. Calls made before the widget has loaded wait and run as soon as it starts.

An "Open chat" button with the unread count
import { useReplyze } from '@replyze/react';

export function HelpButton() {
  const { toggle, unreadCount } = useReplyze();
  return (
    <button type="button" onClick={toggle}>
      Help{unreadCount > 0 ? ` (${unreadCount})` : ''}
    </button>
  );
}

Identity verification

Without verification, identify() only labels the visitor. With it, a signed-in user of your app is the same contact on every device and browser, with their past conversations, marked as verified in the inbox, and nobody can chat as someone else by calling identify() with their email. Turn it on in Settings → Chat Widget → Identity and keep the secret on your server. There, createUserHash() from @replyze/react/server signs the user's id (an HMAC-SHA256, with Web Crypto only), and you pass the user to <ReplyzeChat user={...} />. Passing user={null} after a sign-out resets the chat, so the next person on a shared computer starts fresh.

In practice

How Replyze fits into React and Next.js

@replyze/react loads the same widget as the HTML snippet. The first <ReplyzeChat /> sets window.ReplyzeConfig from its props and adds one async script for https://cdn.replyze.chat/widget.js to <head>. More instances, re-renders and React StrictMode's double effects don't add another. The widget then draws everything inside one shadow root, over the page.

With the default strategy="lazyOnload", widget.js is requested after the page's load event, when the browser is idle. strategy="afterInteractive" requests it right after React has mounted the component. Nothing touches window during render, so it is safe to render on the server: there useReplyze() returns status "idle" and the methods do nothing.

If widget.js is already on the page (the HTML snippet, or a tag manager), <ReplyzeChat /> uses that widget instead of loading a second one. The widget token isn't a secret: it only lets the chat talk to your workspace. API keys (rpz_live_...) are secrets, and <ReplyzeChat /> refuses to load with one.

@replyze/react isn't on the npm registry yet. npm install github:Replyze/react-live-chat installs it from GitHub, and npm builds it while it installs, so the install needs git. You still import it as @replyze/react.

What visitors on React and Next.js get

AI first, your team when it matters

  • Answers from your own help articles

    The AI replies in the visitor's language from the articles you publish and the answers your team teaches it. If the answer isn't there, it says so instead of guessing.

  • A person when it matters

    Visitors can ask for a person at any time, and topics your industry setup marks for the team, such as refunds and complaints, are handed over too. The teammate replies in the same chat, with the whole conversation in front of them.

  • Chat, email and messaging in one inbox

    Web chat on every plan. Email, WhatsApp and Telegram on Pro and Business, with Messenger and Instagram in beta, all in one shared inbox.

See every feature

FAQ

React and Next.js + Replyze, answered

Not yet. Install it from GitHub with npm install github:Replyze/react-live-chat. You import it as @replyze/react. npm builds the package while it installs, so the install needs git.

No. <ReplyzeChat /> loads the widget script itself, works in the App Router and the Pages Router, and gives you hooks and typed events that a bare <Script> tag doesn't. If you'd rather add a plain script tag, the Next.js guide shows the next/script way.

In the Replyze dashboard: Settings → Chat Widget → Launcher, "Pages the widget shows on". Or from code, with hide() and show() from useReplyze(). After show(), the widget shows everywhere regardless of the page rules, so use one or the other.

Check status from useReplyze() and the browser console. "error" with "Could not load https://cdn.replyze.chat/widget.js" is a network error, an ad blocker or your Content-Security-Policy. "Widget blocked: this domain ... is not in the widget's allowed-domains list" means the domain (or localhost while you develop) has to be added in Settings → Chat Widget. "idle" means no <ReplyzeChat /> with a token was mounted.

Yes. react-native-live-chat and flutter-live-chat, both on GitHub under github.com/Replyze, run the same chat inside React Native and Expo apps or Flutter apps.

Get your React and Next.js chat ready for customers

Once the widget is installed, give it useful answers and connect it to the people who will reply. These examples cover what to publish, where to test the chat and how to handle the first enquiries from your React and Next.js site.

Read more: Get your React and Next.js chat ready for customers

What will visitors ask on your React and Next.js site?

“How do I invite my team to my account?” is one question to try. It is the kind of detail a visitor may want while reading a page, before sending a message or making a purchase. Start with the questions your team hears most often about onboarding, account settings and plan questions. Write the answer in a Replyze help article, using the same terms and conditions customers see on the website. Include the next step and a useful link when the customer needs another page.

Open the page where that question is likely to come up and ask it in your own words. Then ask a follow-up: “What if my situation is different?” Read both replies and request a person. This gives you a first check of the answer and the connection to your team before you invite customers to use chat.

A visitor on React and Next.js can ask a question while reading the page and continue with your team.
A visitor on React and Next.js can ask a question while reading the page and continue with your team.

Before and after adding chat to React and Next.js

Before: someone looking for onboarding, account settings and plan questions may search the navigation, open a contact form and wait for an email. A clear website already answers many of these questions, so look for the points where people still get stuck. Your last few customer messages can show which explanation is missing or hard to find.

After: the visitor asks in the widget and receives an answer from the articles you have published. If the question concerns their own order, appointment or account, the team can continue in the same conversation. For example, a general policy question can lead into “Can you check my request?” The first answer stays visible when a colleague takes over, along with the details the customer has already shared.

Example contact journey: a React and Next.js visitor asks on the page and the team can continue the same chat.
Example contact journey: a React and Next.js visitor asks on the page and the team can continue the same chat.

Which help articles should you prepare first?

Create a short article for each of your main topics: onboarding, account settings and plan questions. Explain the usual answer, the conditions that change it and the contact route for an individual request. Use your current website information as the starting point. The widget connects your site to Replyze; add the information you want the assistant to use in the knowledge base as a separate setup step.

If those answers already live in a document, Write with AI can prepare draft articles for you to check. Read the dates, amounts and exceptions carefully before publishing. Remove old versions that disagree with the new answer. When you change a policy on your React and Next.js site, update the corresponding article too so customers get the same explanation in both places.

Prepare help articles about onboarding, account settings and plan questions before opening the chat to customers.
Prepare help articles about onboarding, account settings and plan questions before opening the chat to customers.

Where should the React and Next.js component go?

Render the component once in the root layout, then check a direct page load as well as client-side navigation. Start with the first installation step above: Copy your widget token (wgt_...) from Settings → Integrations → Install widget in your Replyze dashboard. Use the widget token from the Replyze workspace that belongs to this website and follow the remaining platform steps. The workspace setting determines where the messages arrive, so check it before publishing, especially if you manage several brands or client sites.

Render the component once, near the root of the app. If another person previously added chat through a theme, a custom-code setting or a tag manager, locate that copy before adding a new one. Two installations can make troubleshooting confusing. Tell the person maintaining the site where you placed it, so the next theme update or redesign includes the same check.

Use the React and Next.js installation steps and the widget token for this website’s Replyze workspace.
Use the React and Next.js installation steps and the widget token for this website’s Replyze workspace.

What happens when a visitor needs a person?

Try a follow-up that needs somebody to check an individual request: “Can you change this for me?” The chat should explain how to reach the team and keep the conversation available for the person who responds. The website installation provides chat; account changes, order checks and booking confirmations still use the business systems and people responsible for them.

Ask directly for a teammate as well. Open the shared inbox and read the conversation from the receiving person’s side. Can they see what the customer wants and what has already been answered? Set the opening hours and contact instructions your team can actually support. When nobody is available, the customer needs a way to leave a contact detail and a clear expectation for the reply.

A teammate can continue the React and Next.js conversation with the earlier messages available.
A teammate can continue the React and Next.js conversation with the earlier messages available.

Should chat replace your contact form?

Keep a contact form when it helps customers send a detailed enquiry in one go. A project brief, a request involving several products or a message sent outside office hours may suit that format. Chat is useful when somebody has a short question and wants to ask a follow-up while looking at the page. The two contact options can serve the same website.

Try both routes with the question “How do I invite my team to my account?”. Check which one helps the visitor reach an answer comfortably. On a phone, open the chat alongside any cookie notice and the page’s main button. Make sure customers can still continue browsing, submit the form or complete their purchase. Adjust the widget placement through its available settings if it covers an important control.

Keep useful contact options available and check the widget beside your React and Next.js page controls.
Keep useful contact options available and check the widget beside your React and Next.js page controls.

Which React and Next.js pages should you check?

Start with the first page load and two client-side route changes. These checks catch differences between templates and publishing settings that a homepage-only test can miss. Visit each page directly, then navigate between them as a customer would. Confirm that the chat opens and that a message reaches the same intended workspace from each location.

Some parts of a platform have their own code restrictions or access settings. Use the platform instructions above when checking a checkout, customer account or other restricted area. Keep your existing support link available wherever the widget is not installed. A simple list of the pages you have checked helps the website maintainer repeat the right tests after a redesign.

Check the first page load and two client-side route changes after publishing the React and Next.js installation.
Check the first page load and two client-side route changes after publishing the React and Next.js installation.

How can you tell that messages reach the right team?

Send a message labelled “Website chat test” from the published React and Next.js site and find it in Replyze. Reply as a teammate and check that the answer appears in the visitor’s chat. Request a human handover and verify the notification route the team uses. This confirms the path in both directions.

For an agency or a business with several websites, repeat the test for each workspace. Check that the help articles and team access belong to the same business as the site. Ask the colleague who will answer real enquiries to try a reply. They should know where the conversation appears and which contact instructions customers see outside opening hours.

Follow a test message from your React and Next.js website into the team inbox and back to the visitor.
Follow a test message from your React and Next.js website into the team inbox and back to the visitor.

What if the widget is missing on React and Next.js?

First check the published site in a fresh browser window. Confirm that the installation change was saved and published, and follow any cache instructions in the guide above. Render the component once in the root layout, then check a direct page load as well as client-side navigation. Check where the component renders and the token it receives before changing anything else. A missing publish step or a different active template can explain why a change appears in an editor but not on the public website.

Once the widget appears, test typing, opening and closing it on a phone. Navigate to another page and try again. Keep the previous website configuration in your normal version history so the site maintainer can undo a mistaken placement. Removing the component from the website is a separate task from managing the Replyze workspace and its conversations.

If React and Next.js chat is missing, check publication and placement before adding a second component.
If React and Next.js chat is missing, check publication and placement before adding a second component.

What should you update after launch?

Read the first enquiries about onboarding, account settings and plan questions. If several people ask the same question, improve the relevant help article and the page that prompted it. When a reply needs a teammate, check whether that person had enough information to continue. A useful first week often reveals a missing policy detail or a confusing link that is easy to fix.

Repeat the installation check after a theme change, a new template or a platform migration. Repeat the answer check when your services or policies change. Give the website maintainer the page list and give the support team the sample questions. That keeps both parts of your React and Next.js chat working as the site grows.

Keep the React and Next.js installation and the answers about onboarding, account settings and plan questions up to date.
Keep the React and Next.js installation and the answers about onboarding, account settings and plan questions up to date.

Let AI answer the questions you get every day

Teach it your answers, pick your colours and add it to your site. When a customer needs a person, your team takes over.

Card required · Cancel before day 15 and pay nothing. No card? Start on the Free plan, with 50 AI replies once for a new account's first month.