Custom Trigger
Control when the agent opens using React state.
The open Prop
The <Char> component accepts an open prop to control visibility:
import { useState } from 'react';import { Char } from '@mcp-b/char';
function App() { const [isOpen, setIsOpen] = useState(false);
return ( <> <button onClick={() => setIsOpen(true)}> Chat with AI </button> <Char open={isOpen} onOpenChange={setIsOpen} devMode={{ anthropicApiKey: "demo" }} /> </> );}Props Explained
| Prop | Type | Description |
|---|---|---|
open | boolean | Controls whether the chat is open |
onOpenChange | (open: boolean) => void | Called when open state changes |
Hiding the Default Trigger
To hide the floating bubble entirely:
<Char open={isOpen} onOpenChange={setIsOpen} trigger={false} devMode={{ anthropicApiKey: "demo" }}/>Try it
Add a custom “Chat with AI” button. When clicked, it should open the agent.
Files
Preparing Environment
- npm install
- npm run dev