LuxelEspañol

Luxel v0.1 · Guide · part 1 of 2

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.jsLuxelNotes
useState for server dataA state path in the contract, bind in the viewNo 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 mountdefineLoadRuns on the server per request; the page arrives complete. No loading state
fetch / a server action in an event handler‹Action event> + defineEventOne endpoint, POST /_luxel/event; the runtime sends it
onClick, onChange, onSubmit‹Action event>; changeEvent on row collectionsFunction props are LUXEL-E001
PropsProps of your own helper components, evaluated at build timeStatic 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 viewFine: it runs at build time
keyitemKey on CollectionLUXEL-E008 without it
{cond && ‹X />} on dataThe server decides: an empty text, an empty collection, a status field with stateClasses, disabled: true on an item, or another viewcond && ‹X /> works only for conditions known at build time
Loading spinners, disabled={saving}busyLabel, busyClassName on ActionThe runtime drops a second click while in flight
Error banners from catch‹Status> + ctx.rejectThe server's message, in the action's status zone
Client-side validationctx.reject('VALIDATION', ctx.message(…)) in the handlerrequired, maxLength, integer bounds and dates are also re-checked by the framework
Intl.NumberFormat / toLocaleString in the componentmoney(), date(), quantity() leavesThe host formats; money is integer cents
style={{…}}, inline stylesclassName + your stylesheetLUXEL-E010; the CSP forbids inline styles
‹div>, ‹button>, any HTMLStack, Row, Text, Action…LUXEL-E004
dangerouslySetInnerHTMLNoneText is always text
A chart library computing scalesChart, Bar, with the scale from the serverSee 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 timeNo query, parameter or other site
router.push after something happensAn 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 handlersNo endpoint per resource
Middleware auth, redirectsviews.‹id>.loginView, whenAuthenticated, contract policies (allow, publicEvent)Deny by default
Checking ownership in an API routeScope functions (bindings.scopes) + refsAn id of another user answers like an unknown id
Edit this page on GitHub

This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app.

Measured when the site is built: the runtime files this page loads, compressed as they are sent.

Made by IntiOps. Luxel 0.1.0-beta.1 is a beta: no external security review yet.