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.
@loopwix/sdk) is planned but not released yet. Use the script embed below; it works in any React or Next.js app.How do I add the chat to a Next.js 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)
Load the script once in your root layout, with your public key from Channels → Website chat → Install:
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) and check CSP if you use one.
React (Vite, Create React App)
Add the same script tag to index.html before </body>:
<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
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:
<button data-loopwix-open>Chat with us</button>For programmatic control see the JavaScript API.
Single-page-app tips
- Do not mount the script inside a component that re-renders on every navigation.
- In development, add
localhostto your allowed sites. - For server rendering, the widget loads on the client only; nothing renders on the server.
Embed the widget
Embed the Loopwix chat widget with one script tag, show it in a page or open it from your own button, control it from JavaScript and set your CSP.
Hosted chat page and public widget API
Link to the full-page hosted Loopwix chat, and see an overview of the public endpoints the chat widget uses, with how stable each one is today.