Connect components to your app
Each component shows the values you pass in and calls a function when someone interacts with it. Your app decides what happens next.
Start with a value and a callback
A controlled component gets its current value from your app. When the user edits it, the component calls your callback. Update the value in your app and pass it back.
import { useState } from 'react';
import { Input } from '@stackunseen/ui';
export function ProjectName() {
const [name, setName] = useState('My project');
return (
<label>
Project name
<Input value={name} onChange={(event) => setName(event.target.value)} />
</label>
);
}Here, value is what the input displays. onChange receives the edit. This example changes local state; saving the project is a separate action in your app.
Read the component page in three steps
- Try the example. Change its state or style to see the behavior you need.
- Read Usage and props. It explains the values and callbacks used by the example.
- Open Code. Copy the imports and component usage, then connect its values to your own state.
An optional prop is marked in its type. The example lists the main props; your editor can show the full TypeScript API.
Use @stackunseen/ui for React components. Use @stackunseen/ui-core when you need the shared AI state types and validation. If you connect an AI provider, translate its events into those types before passing them to the UI.
Connect an action to your server
A callback such as onSubmit or onAction tells you what the user requested. Send that request to your server. Keep the draft or selected values until the server confirms the result, and show any error it returns.
For a composer, this means keeping value in your app, passing edits through onValueChange, and connecting onSubmit to your message request. Set busy while that request is pending. Clear the draft after the server accepts it.
For everyday UI state, such as an open dialog or a selected tab, local React state is enough. Running tools, changing access and approving actions need your server to confirm them.
Approve the exact action being shown
An approval must identify the action, its current version and the records it affects. If any of those change, ask again. Show a decision as accepted only after your server confirms that exact request.
For example, approval to archive two accounts does not cover a revised request to archive three. The ApprovalCard displays the proposal and collects the decision; your server checks whether it can run.
The action and receipt example walks through a proposed change, the decision and the confirmed result, using a simulated server.
Handle a lost connection carefully
If the connection drops after you send a request, the action may already have run. Keep the original request ID and check its result before you send it again. Until you know, say the outcome isn't confirmed yet, rather than showing success or failure.
ConnectionStatus and RunInspector show a lost connection, out-of-date data and an unconfirmed request as three different things.
The recoverable chat example shows how to keep a draft and check whether the original request went through after an interruption.
Keep model output as content
Show model text, tool results and source excerpts with the library's renderers. Never run generated code or raw MDX. Only show progress and results that your server actually reports.
The research answer example puts each claim next to its sources and marks anything without one.
Test your own integration
Test denied requests, changed approvals, cancellation, failures and reconnection against your server. Check keyboard focus and narrow screens with your real content. The gallery and app examples use sample data; they do not verify your authentication, storage or AI provider.