## Demo: form-return-data ### FormReturnData.svelte ```svelte

A minimal action that returns a random number via success({'{ value }'}). The hydrated version updates the input reactively; the non-hydrated version re-renders the whole page and the component reads the value from getRequestContext().form.

With {'{@attach enhance(...)}'}

Plain HTML

``` ### RandomRoll.svelte ```svelte

{label}

``` ### routes.ts ```ts import { Mochi, success } from 'mochi-framework'; import type { MochiRouteValue } from 'mochi-framework'; export const routes: Record = { '/demos/form-return-data': Mochi.page('./src/demos/form-return-data/FormReturnData.svelte', { actions: { random: () => success({ value: Math.floor(Math.random() * 100) + 1 }), }, }), }; ``` ### index.ts ```ts import { Mochi, logger } from 'mochi-framework'; await Mochi.serve({ port: 3333, development: process.env.MODE === 'development', routes: { '/': Mochi.page('./src/Home.svelte'), }, }); logger.info('Server running at http://localhost:3333'); ```