Examples
Example — React App (npm)
Embed the widget inside a bundled React app with the npm package
For a React app with a bundler (Vite, Next.js, Create React App), install the package and render the component once near the root.
Install
npm install @wexio/messenger-widget-reactComponent
import { useMemo } from "react";
import { WexioWidget } from "@wexio/messenger-widget-react";
export function ChatWidget({ currentUser, wexioJwt }) {
// Memoise the identity so the widget doesn't re-handshake every render.
const user = useMemo(
() =>
wexioJwt
? { jwt: wexioJwt, name: currentUser?.name, email: currentUser?.email }
: undefined,
[wexioJwt, currentUser?.name, currentUser?.email],
);
return (
<WexioWidget
publicKey="pk_live_..."
user={user}
onOpen={() => console.log("widget opened")}
onClose={() => console.log("widget closed")}
/>
);
}Mount it once at the app root:
export default function App() {
return (
<>
<YourAppShell />
<ChatWidget currentUser={currentUser} wexioJwt={wexioJwt} />
</>
);
}Next.js note
The component returns null on the server and mounts on the first client effect, so it's safe in the App Router or Pages Router. If you sign the JWT in a server component or route handler, pass it down as a prop (as wexioJwt above) — never expose your shared secret to the client.
What to change
| Token | Replace with |
|---|---|
pk_live_... | Your public key. |
wexioJwt | A server-signed JWT — omit user entirely for anonymous visitors. |
Related
- React component reference — full prop list and types.
- Signed JWT — how to mint the token server-side.