diff --git a/packages/react/README.md b/packages/react/README.md new file mode 100644 index 00000000..8e34af69 --- /dev/null +++ b/packages/react/README.md @@ -0,0 +1,35 @@ +# @chatcops/react + +`` and `useChatCops()` for React and Next.js. The component loads `@chatcops/widget` in an effect on the client and renders nothing itself, so it's safe in server-rendered pages and server components. + +```bash +npm install @chatcops/react @chatcops/widget +``` + +```tsx +'use client'; + +import { ChatCops, useChatCops } from '@chatcops/react'; + +export function Chat() { + return ( + console.log('Lead captured:', lead)} + /> + ); +} + +export function AskButton({ productName }: { productName: string }) { + const chat = useChatCops(); + return ; +} +``` + +- `` takes every `WidgetConfig` option, plus `onOpen`, `onClose`, `onMessage`, `onError`, `onLeadCaptured` and `onPreChatSubmit`. Render one per page. A second one replaces the first, as a second `ChatCops.init()` does. +- Changes to `branding`, `welcomeMessage`, `suggestions`, `placeholder`, `strings`, `privacyUrl`, `disclosure` and `theme` (except `position`) go through `ChatCops.update()`. Any other change starts the widget over, which closes the panel and stops a reply in progress. +- The event props and the `userToken` and `onConsentRequest` functions are read through refs, so a new inline function on each render doesn't restart the widget. +- `useChatCops()` returns `open()`, `close()`, `toggle()`, `send(text, { open })` and `update(changes)`. Until the widget has loaded they do nothing, and `send()` resolves right away. + +React 18 or later, Node 22 or later. Full guide: https://chat.codercops.com/widget/react/ diff --git a/packages/react/package.json b/packages/react/package.json index ecb67219..71af98b7 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -2,7 +2,6 @@ "name": "@chatcops/react", "version": "0.1.0", "description": "React component and hooks for ChatCops", - "private": true, "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -50,6 +49,9 @@ "url": "git+https://github.com/codercops/chatcops.git", "directory": "packages/react" }, + "publishConfig": { + "access": "public" + }, "license": "MIT", "engines": { "node": ">=22"