Modern React component for Tawk.to messenger with TypeScript, React 19, and Next.js 13+ support
npm install tawk-react-widget

Modern React component for Tawk.to live chat messenger
- โ๏ธ React 19 Support - Full compatibility with the latest React version
- ๐ TypeScript First - Written in TypeScript with comprehensive type definitions
- โก Next.js 13+ Ready - Built-in support for both App Router and Pages Router
- ๐ช React Hooks - Modern hooks-based API
- ๐ฏ Fully Typed API - All Tawk.to JavaScript API methods with TypeScript support
- ๐ฆ Zero Dependencies - No external runtime dependencies (except React peer deps)
- ๐ง ESM & CJS - Dual module format support
- ๐งช Well Tested - Comprehensive test coverage with Vitest
- ๐ Documented - Extensive documentation and examples
- ๐ Optimized - Small bundle size, tree-shakeable
``bashnpm
npm install tawk-react-widget
๐ Quick Start
$3
`tsx
import TawkMessenger from 'tawk-react-widget';function App() {
return (
My Application
);
}export default App;
`$3
`tsx
// app/layout.tsx
import { TawkMessenger } from 'tawk-react-widget/nextjs';export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
{children}
);
}
`$3
`tsx
// pages/_app.tsx
import type { AppProps } from 'next/app';
import { TawkMessenger } from 'tawk-react-widget/nextjs';export default function App({ Component, pageProps }: AppProps) {
return (
<>
>
);
}
`๐ฏ Getting Your Credentials
1. Log in to your Tawk.to Dashboard
2. Go to Administration โ Channels โ Chat Widget
3. Copy your Property ID and Widget ID
๐ Usage with Ref
Control the widget programmatically using refs:
`tsx
import { useRef } from 'react';
import TawkMessenger, { TawkMessengerRef } from 'tawk-react-widget';function App() {
const tawkRef = useRef(null);
const handleOpenChat = () => {
tawkRef.current?.maximize();
};
const handleMinimizeChat = () => {
tawkRef.current?.minimize();
};
return (
);
}
`๐ง API Reference
$3
| Prop | Type | Required | Default | Description |
| ---------------------- | --------------------------- | -------- | ----------- | -------------------------------- |
|
propertyId | string | โ
| - | Your Tawk.to Property ID |
| widgetId | string | โ
| - | Your Tawk.to Widget ID |
| embedId | string | โ | '' | ID for embedded widget mode |
| basePath | string | โ | 'tawk.to' | Custom base path for self-hosted |
| autoStart | boolean | โ | true | Auto-start the widget |
| customStyle | object | โ | undefined | Custom widget styling |
| onLoad | () => void | โ | - | Called when widget loads |
| onStatusChange | (status: string) => void | โ | - | Called when status changes |
| onChatStarted | () => void | โ | - | Called when chat starts |
| onChatEnded | () => void | โ | - | Called when chat ends |
| onChatMaximized | () => void | โ | - | Called when chat is maximized |
| onChatMinimized | () => void | โ | - | Called when chat is minimized |
| onChatMessageVisitor | (message: string) => void | โ | - | Called on visitor message |
| onChatMessageAgent | (message: string) => void | โ | - | Called on agent message |$3
All methods are available through the component ref:
`typescript
interface TawkMessengerRef {
// Widget Control
maximize(): void;
minimize(): void;
toggle(): void;
popup(): void;
showWidget(): void;
hideWidget(): void;
toggleVisibility(): void;
endChat(): void; // Widget State
getWindowType(): 'inline' | 'popup' | null;
getStatus(): 'online' | 'away' | 'offline';
isChatMaximized(): boolean;
isChatMinimized(): boolean;
isChatHidden(): boolean;
isChatOngoing(): boolean;
isVisitorEngaged(): boolean;
// Visitor Management
setVisitor(data: Record): void;
setAttributes(attributes: Record, callback?: (error: Error | null) => void): void;
addEvent(
event: string,
metadata?: Record,
callback?: (error: Error | null) => void
): void;
addTags(tags: string[], callback?: (error: Error | null) => void): void;
removeTags(tags: string[], callback?: (error: Error | null) => void): void;
}
`๐ Examples
examples directory for more detailed examples:- Next.js App Router
- Next.js Pages Router
- React with Ref
- Full TypeScript Example
๐งช Testing
`bash
Run tests
npm testRun tests in watch mode
npm run test:watchGenerate coverage report
npm run test:coverage
`๐๏ธ Building
`bash
Build the package
npm run buildType check
npm run typecheck
``For detailed documentation, see:
- How to Use - Comprehensive usage guide
- API Reference - Complete API documentation
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
This package is a modern TypeScript fork of @tawk.to/tawk-messenger-react with additional features and improvements.
- Tawk.to Website
- Tawk.to JavaScript API Documentation
- GitHub Repository
- npm Package
For issues, questions, or contributions, please visit our GitHub Issues.