0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/client-sdks/react/README.md
Lennart e983f74987
chore(*): Update/unify/add READMEs (#22858)
Co-authored-by: Mastra Code (openai/gpt-5.6-sol) <noreply@mastra.ai>
2026-09-02 14:36:59 +02:00

2.1 KiB

@mastra/react

@mastra/react provides React context, hooks, message utilities, voice helpers, and UI primitives for applications that connect to a Mastra server. Wrap the application once with MastraReactProvider, then access the configured client throughout the component tree.

Installation

npm install @mastra/react

Usage

import { MastraReactProvider } from '@mastra/react';

export function App({ children }: { children: React.ReactNode }) {
  return <MastraReactProvider baseUrl="http://localhost:4111">{children}</MastraReactProvider>;
}

Documentation

MastraReactProvider constructs and shares the Mastra client. In addition to baseUrl, it accepts custom headers, an API prefix, fetch credentials, and a custom fetch implementation for applications that need authentication or request instrumentation. Use useMastraClient() when a component needs direct access to the underlying client.

The package exports agent hooks such as useChat for generated or streamed conversations, including optimistic messages, tool calls, approvals, task signals, aborts, and reconnection to active runs. It also exports workflow hooks and WorkflowStepFactory for consuming workflow state and streamed step results.

Voice helpers include browser speech recognition, microphone recording, and Web Audio playback. Message utilities expose Mastra's database message types and accumulation helpers, while the @mastra/react/ui entry point provides reusable message, code, icon, button, entity, and tooltip components. Import @mastra/react/styles.css when using the packaged UI components.

React 19 or newer is required. The package also expects compatible versions of @mastra/core and Zod in the consuming application.

Changelog

See the package changelog for version history and release notes.

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.