React

React hooks, provider, and components

Full React integration with hooks and components.

npm install @yourgpt/copilot-sdk/react


Quick Start

import { CopilotProvider, useCopilot, useTools } from '@yourgpt/copilot-sdk/react';
import { CopilotChat } from '@yourgpt/copilot-sdk/react';

function App() {
  return (
    <CopilotProvider runtimeUrl="/api/chat">
      <MyTools />
      <CopilotChat />
    </CopilotProvider>
  );
}

function MyTools() {
  useTools({
    search: {
      description: 'Search products',
      parameters: z.object({ query: z.string() }),
      handler: async ({ query }) => searchProducts(query),
    },
  });
  return null;
}

On this page