Data and actions
With sections alone, users can rearrange, resize, hide and restyle what's already on the page. Give Morph some of your data, and they can also ask for new views of it: "a banner with my overdue invoices", "a short list of customers who haven't paid". Give it actions, and those views can have buttons: "…with a Send reminder button on each".
Both are optional, and both stay in your app: Morph's servers never see the values.
Data#
Pass whatever the page may show, already filtered for the signed-in user:
<MorphSurface id="dashboard" data={data}>
usemorph sync reads the TypeScript type of data and gives the AI a description of it, including your doc comments. Good types and comments make better views:
interface AppData {
invoices: InvoiceRow[];
stats: {
/** Dollars paid this month. */
revenueThisMonth: number;
/** Count of unpaid invoices. */
openInvoices: number;
};
/** Revenue in $ thousands for the last 6 months, oldest first. */
revenueTrend: number[];
}
The AI never sees the data itself, only this description. In the user's browser, new views read the real values from the data you passed. When your data changes (you re-render with new data), the views update.
Only pass what this user may see. Morph shows what you give it; your server stays responsible for permissions.
npm init usemorph@latest passes each page's data for you: it picks the variables the page already has (for example tasks, projects, stats) and writes data={{ tasks, projects, stats }}. Check the diff it shows you; remove anything a user shouldn't build views from.
Values users enter#
Some features need to remember something your app has nowhere to keep: a weekly target, notes on a project, a pinned list. Pages Morph builds keep these with useSaved, which works like React's useState but is stored per user in Morph's database (up to 100 values per page, 16 KB each):
const [goal, setGoal] = useSaved("monthly-goal", 50000);
They're never your app's records: those stay in your database and reach pages through data. To keep these values for the visit only, set savedValues: false in morph.config.ts.
Actions#
Actions are your own functions that new views may put on buttons:
const actions = {
invoices: {
/** Email the customer a payment reminder (unpaid invoices only). */
send_reminder: (id: string) => sendReminder(id),
/** Record that the invoice was paid (unpaid invoices only). */
mark_paid: (id: string) => markPaid(id),
},
};
<MorphSurface id="dashboard" data={data} actions={actions}>
- Group actions by what they act on (
invoices), and name them insnake_case. - Each gets the id of the row it's for, and may return a short message to show the user ("Reminder sent.").
syncreads the names and the doc comments, so the AI knows what each one does.
Safety: pages can only call the actions you list, and only right after the user clicks or types, so a page can't run an action on its own. Your functions run your normal code, with your normal permission checks.
What AI-written pages can use#
Pages the AI writes can only import three modules:
| Module | What's in it |
|---|---|
react |
React |
@company |
Your sections (and any components you list in morph.config.ts) |
@morph |
useCompanyData() (your data), useAction() (your actions), useSaved() (values the user enters), a Panel card, and helpers like money() and shortDate() |
No network requests, no browser storage, no access to the rest of the page. Morph checks this on its server before any page runs.