# React and Next.js (/docs/developers/react-and-next-js)

> Add the Loopwix chat to a React or Next.js app today with the script embed, and what to expect from the planned React package.

Type: how-to | Status: beta | Last reviewed: 2026-11-21 | Minimum role: builder

<Callout type="warn">A dedicated React package (`@loopwix/sdk`) is **planned but not released yet**. Use the script embed below; it works in any React or Next.js app.</Callout>

## How do I add the chat to a Next.js or React app? [#how-do-i-add-the-chat-to-a-nextjs-or-react-app]

Load the Loopwix script once, with your public key from the website chat Install tab. In Next.js, add it to your root layout with the Script component. In a Vite or Create React App project, add it to your page. A dedicated React package is planned but not released yet.

## Next.js (App Router) [#nextjs-app-router]

Load the script once in your root layout, with your **public key** from **Channels → Website chat → Install**:

```tsx
import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script src="YOUR_WIDGET_SCRIPT_URL" data-key="lwix_pub_..." strategy="afterInteractive" />
      </body>
    </html>
  );
}
```

Copy the exact script URL from the Install tab. Add your site's domain to the allowed sites ([Public keys and allowed sites](/docs/developers/embed-the-widget#public-keys-and-allowed-sites)) and check [CSP](/docs/developers/embed-the-widget#csp-cookies-and-privacy) if you use one.

## React (Vite, Create React App) [#react-vite-create-react-app]

Add the same script tag to `index.html` before `</body>`:

```html
<script src="YOUR_WIDGET_SCRIPT_URL" data-key="lwix_pub_..." defer></script>
```

Load it once in the page shell, not on every route.

## Open the chat from your own button [#open-the-chat-from-your-own-button]

On the website chat **Install** tab, set **How it appears** to **Opens from a button** and **Button** to **My own button**. Then add `data-loopwix-open` to your element:

```tsx
<button data-loopwix-open>Chat with us</button>
```

For programmatic control see the [JavaScript API](/docs/developers/embed-the-widget#javascript-api).

## Single-page-app tips [#single-page-app-tips]

- Do not mount the script inside a component that re-renders on every navigation.
- In development, add `localhost` to your allowed sites.
- For server rendering, the widget loads on the client only; nothing renders on the server.
