Repository navigation
Framework Guides
The widget is a client component: it uses state, effects and window. The package entry already has the "use client" directive. It needs React 18 or 19.
Render it in the root layout. You can import it directly into a Server Component, as long as you only pass plain values (strings, numbers, booleans, objects, arrays):
// app/layout.tsx
import { WhatsAppChat } from 'whatsapp-chat-widget-react';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<WhatsAppChat phoneNumber="+12025550123" />
</body>
</html>
);
}Functions cannot cross from a Server Component to a Client Component. If you need onSend, messageTemplate, onOpenChange or other callbacks, wrap the widget in your own client component:
// components/Chat.tsx
'use client';
import { WhatsAppChat } from 'whatsapp-chat-widget-react';
export function Chat() {
return <WhatsAppChat phoneNumber="+12025550123" onSend={(d) => console.log(d)} />;
}hideOnPaths follows App Router navigation, so hideOnPaths={['/checkout/*']} works without reading the pathname yourself.
// pages/_app.tsx
import type { AppProps } from 'next/app';
import { WhatsAppChat } from 'whatsapp-chat-widget-react';
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Component {...pageProps} />
<WhatsAppChat phoneNumber="+12025550123" />
</>
);
}// src/App.tsx
import { WhatsAppChat } from 'whatsapp-chat-widget-react';
export default function App() {
return (
<>
{/* ...routes... */}
<WhatsAppChat phoneNumber="+12025550123" />
</>
);
}Render it once in app/root.tsx, inside the body:
import { WhatsAppChat } from 'whatsapp-chat-widget-react';
export default function App() {
return (
<html lang="en">
<head>{/* ... */}</head>
<body>
<Outlet />
<WhatsAppChat phoneNumber="+12025550123" />
<Scripts />
</body>
</html>
);
}If your toolchain handles ESM packages and React, it works. Render the component once, high in the tree and outside any element with a CSS transform, filter or perspective, because those make position: fixed relative to that element instead of the screen.
createWebhookTransport and createOpenAICompatibleAI live in whatsapp-chat-widget-react/adapters. In Next.js, use the transport and AI objects from a client component (the same file as the widget, or one marked 'use client'), and create them at module level so the same object is used on every render. Keep AI provider keys in an API route, never in client code: see Backend Recipes. With TypeScript, the adapters path needs moduleResolution of node16, nodenext or bundler (the defaults in current Next.js and Vite templates).
The initial HTML contains the launcher and, if you set defaultOpen, the form. Business-hours status, page context, showAfter and hideOnPaths are all resolved after mount, so server and client markup match and React reports no hydration mismatch.
The widget adds one inline <style> element. If your CSP blocks inline styles, set injectStyles={false} and import whatsapp-chat-widget-react/styles.css so your bundler serves it as a normal stylesheet. See Styling and Theming.
The component renders in jsdom (Vitest, Jest with ESM support). Business-hours status needs timers: use fake timers and set the system time. The widget refreshes the status once a minute.