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
History 2026-11-12 21:12:29 +00:00
..
.storybook chore: migrate linting to oxlint (#20173) 2026-07-25 01:04:02 +02:00
src feat(ui): one settings layout across Studio, Factory and Platform (#29400) 2026-11-12 18:05:50 +04:00
CHANGELOG.md chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
lint-staged.config.js refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
oxlint.config.ts refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
package.json chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
README.md chore(*): Update/unify/add READMEs (#22858) 2026-09-02 14:36:59 +02:00
tsconfig.build.json Move Studio data hooks to a public @mastra/react/hooks entry (#25916) 2026-10-05 09:10:00 +02:00
tsconfig.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
tsdown.config.ts feat(react): split @mastra/react/hooks into per-domain entries (#25950) 2026-10-05 16:30:29 +02:00
turbo.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
vite.config.ts fix(react,playground): externalize @mastra/core and stub Node builtins (#13703) 2026-03-03 11:25:27 -08:00
vitest.config.ts Move Studio data hooks to a public @mastra/react/hooks entry (#25916) 2026-10-05 09:10:00 +02:00

@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.