This guide covers how to integrate the IllumiChat widget into React and Next.js applications, including component patterns, TypeScript support, and programmatic control.
Basic Next.js Integration
The recommended approach for Next.js uses the next/script component:
Add it to your root layout so it loads on every page:
The 'use client' directive is required because next/script uses browser APIs. The widget itself is loaded asynchronously and will not affect your server-side rendering.
Configurable Component
Create a reusable component that accepts configuration props:
Usage:
Programmatic Control
Use the global IllumiChat API to control the widget from your React components:
TypeScript Declarations
Add type declarations for the global API:
Event Handling
Listen to widget events using a custom hook:
Use it in your layout or page component:
Conditional Loading
Load the widget only on specific pages or for specific users:
Pass user identity to the widget for authenticated conversations:
Avoid passing sensitive user data through data attributes. The widget is client-side JavaScript and data attributes are visible in the DOM.
Plain React (non-Next.js)
For React apps without Next.js, load the script manually:
Environment-Based Configuration
Use environment variables to manage different assistants across environments: