Migrating from React and Next.js
Luxel views look like JSX, but the mental model is the opposite of a client-side React app. In React the browser holds state, fetches data and computes what to show. In Luxel the server holds state, computes everything and fills a compiled template; the browser shows it and sends events.
This page maps React habits to Luxel, then walks through four screens of a real application, the pilot application (distribution and consignment of publications), that exists both as a Next.js app and as a Luxel pilot. The excerpts are real code, shortened. Data values are placeholders.
For the mistakes React developers typically make in Luxel, each with its diagnostic, see react-mistakes.md.
Mapping table
| React / Next.js | Luxel | Notes |
|---|---|---|
| useState for server data | A state path in the contract, bind in the view | No hooks at all (LUXEL-E003). The view runs once, at build time |
| useState for form inputs (controlled inputs) | ‹Field name> | The typed value lives in the input; the action sends it. onSuccess={{ clear }} replaces setForm(EMPTY) |
| useEffect(() => { fetch… }, []) on mount | defineLoad | Runs on the server per request; the page arrives complete. No loading state |
| fetch / a server action in an event handler | ‹Action event> + defineEvent | One endpoint, POST /_luxel/event; the runtime sends it |
| onClick, onChange, onSubmit | ‹Action event>; changeEvent on row collections | Function props are LUXEL-E001 |
| Props | Props of your own helper components, evaluated at build time | Static only. Per-user data comes through bind |
| items.map(...) over fetched data | ‹Collection bind itemKey maxItems> | The item template runs once with placeholders |
| items.map(...) over a constant array | .map() in the view | Fine: it runs at build time |
| key | itemKey on Collection | LUXEL-E008 without it |
| {cond && ‹X />} on data | The server decides: an empty text, an empty collection, a status field with stateClasses, disabled: true on an item, or another view | cond && ‹X /> works only for conditions known at build time |
| Loading spinners, disabled={saving} | busyLabel, busyClassName on Action | The runtime drops a second click while in flight |
| Error banners from catch | ‹Status> + ctx.reject | The server's message, in the action's status zone |
| Client-side validation | ctx.reject('VALIDATION', ctx.message(…)) in the handler | required, maxLength, integer bounds and dates are also re-checked by the framework |
| Intl.NumberFormat / toLocaleString in the component | money(), date(), quantity() leaves | The host formats; money is integer cents |
| style={{…}}, inline styles | className + your stylesheet | LUXEL-E010; the CSP forbids inline styles |
| ‹div>, ‹button>, any HTML | Stack, Row, Text, Action… | LUXEL-E004 |
| dangerouslySetInnerHTML | None | Text is always text |
| A chart library computing scales | Chart, Bar, with the scale from the server | See Charts |
| File-based routing (app/agencias/page.tsx) | One file per view (src/views/agencies.view.tsx), served at /‹variant>/‹view>, or at the static path it declares (Routes) | No route parameters yet (below) |
| ‹Link href="/orders"> to a fixed page | ‹Link to="orders"> (Sprint 12.1): a plain ‹a href> fixed at build time | No query, parameter or other site |
| router.push after something happens | An Action whose handler returns ctx.navigate('view') | Navigation after an event is the server's |
| useParams, /agencias/[id] | A selection kept by the server (an event with param stores it, then navigate) | Views have no route parameter today |
| API routes (app/api/.../route.ts) | defineEvent handlers | No endpoint per resource |
| Middleware auth, redirects | views.‹id>.loginView, whenAuthenticated, contract policies (allow, publicEvent) | Deny by default |
| Checking ownership in an API route | Scope functions (bindings.scopes) + refs | An id of another user answers like an unknown id |