This document shows how to use the CortiEmbeddedReact component with the current React API.
npm install @corti/embedded-webimport React, { useRef } from "react";
import {
CortiEmbeddedReact,
type CortiEmbeddedEvent,
type CortiEmbeddedReadyEvent,
type CortiEmbeddedReactRef,
type CortiEmbeddedErrorDetail,
} from "@corti/embedded-web/react";
function App() {
const cortiRef = useRef<CortiEmbeddedReactRef>(null);
const handleEvent = (event: CortiEmbeddedEvent) => {
console.log(event.detail.name, event.detail.payload);
};
const handleError = (event: CustomEvent<CortiEmbeddedErrorDetail>) => {
console.error("Embedded error:", event.detail);
};
const handleReady = (event: CortiEmbeddedReadyEvent) => {
console.log("Corti embedded is ready", event.detail);
};
return (
<CortiEmbeddedReact
ref={cortiRef}
baseURL="https://assistant.eu.corti.app"
visibility="visible"
onReady={handleReady}
onEvent={handleEvent}
onError={handleError}
style={{ width: "100%", height: "600px" }}
/>
);
}Use onEvent as the canonical event listener.
- Event shape:
CustomEvent<{ name: string; payload: unknown }> onEventreceives the wrapper's genericeventCustomEvent- That generic stream includes
embedded.readyand other forwarded embedded events onReadylistens to the rawembedded.readyCustomEvent- Raw
ready,loaded, anderror.triggeredare not forwarded throughonEvent onErrorreceives the rawCustomEvent, so useevent.detail- Event names and payload contracts are documented publicly at:
Use useCortiEmbeddedApi(ref) to get stable API methods bound to your component instance.
import React, { useRef } from "react";
import {
CortiEmbeddedReact,
type CortiEmbeddedReactRef,
useCortiEmbeddedApi,
} from "@corti/embedded-web/react";
function ApiExample() {
const ref = useRef<CortiEmbeddedReactRef>(null);
const api = useCortiEmbeddedApi(ref);
const run = async () => {
await api.auth({
access_token: "...",
token_type: "Bearer",
// ... rest of the token response
});
const created = await api.createInteraction({
encounter: {
identifier: `encounter-${Date.now()}`,
status: "planned",
type: "first_consultation",
period: { startedAt: new Date().toISOString() },
},
});
await api.configureSession({ defaultTemplateKey: "soap_note" });
await api.addFacts([{ text: "Chest pain", group: "other" }]);
await api.navigate(`/session/${created.id}`);
await api.startRecording();
await api.stopRecording();
const status = await api.getStatus();
await api.configure({ features: { aiChat: false } });
await api.setCredentials({ password: "..." });
api.show();
api.hide();
console.log(status);
};
return (
<>
<button onClick={() => void run()}>Run API Flow</button>
<CortiEmbeddedReact ref={ref} baseURL="https://assistant.eu.corti.app" />
</>
);
}This avoids singleton DOM lookup and works correctly with multiple embedded instances.
Use useCortiEmbeddedStatus(ref) to keep latest status in React state.
The hook returns:
status: latest value fromgetStatus()(ornullbefore first fetch)isLoading:truewhile a status fetch is in progresserror: last fetch error (if any)lastEvent: latest received embedded event ({ name, payload }) used for refresh decisions
How it works:
- It fetches status when mounted (if enabled).
- It listens to
eventfrom the mounted component and automatically refreshes status on incoming events. - Internal filtering avoids refresh recursion from status request/response events.
Suggested usage:
- Mount one
CortiEmbeddedReactinstance and pass the same ref to the hook. - Use
statusfor rendering UI state. - Keep event-specific logic in
onEventwhile letting the hook handle status synchronization.
import React, { useRef } from "react";
import {
CortiEmbeddedReact,
type CortiEmbeddedReactRef,
useCortiEmbeddedStatus,
} from "@corti/embedded-web/react";
function StatusExample() {
const ref = useRef<CortiEmbeddedReactRef>(null);
const { status, isLoading, error, lastEvent } = useCortiEmbeddedStatus(ref);
return (
<div>
<div>Loading: {String(isLoading)}</div>
<div>Last Event: {lastEvent?.name ?? "none"}</div>
<pre>{JSON.stringify(status, null, 2)}</pre>
{error ? <pre>{String(error)}</pre> : null}
<CortiEmbeddedReact ref={ref} baseURL="https://assistant.eu.corti.app" />
</div>
);
}