import { PropertyReference, LinkToCopilotCloud } from "@/components";
import { Tabs } from "nextra/components";
import { Callout } from "nextra/components";
useCopilotChat is a React hook that lets you directly interact with the
Copilot instance. Use to implement a fully custom UI (headless UI) or to
programmatically interact with the Copilot instance managed by the default
UI.
import { useCopilotChat } from "@copilotkit/react-core";
import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
export function YourComponent() {
const { appendMessage } = useCopilotChat();
appendMessage(
new TextMessage({
content: "Hello World",
role: Role.User,
}),
);
}useCopilotChat returns an object with the following properties:
const {
visibleMessages, // An array of messages that are currently visible in the chat.
appendMessage, // A function to append a message to the chat.
setMessages, // A function to set the messages in the chat.
deleteMessage, // A function to delete a message from the chat.
reloadMessages, // A function to reload the messages from the API.
stopGeneration, // A function to stop the generation of the next message.
isLoading, // A boolean indicating if the chat is loading.
} = useCopilotChat();