| name | cradova |
| description | Build web applications with Cradova - a lightweight reactive framework. Use when working with Cradova, creating web apps, building SPAs, or comparing frontend frameworks. Includes guidance on Signal-based state, hooks, routing, and performance optimization. |
Cradova Framework
Cradova is a lightweight, reactive UI framework for building web applications. It uses direct DOM manipulation (no virtual DOM), signal-based pub/sub reactivity, and a VJS (Virtual JavaScript) specification instead of JSX.
When to Use Cradova
- Building SPAs or PWAs
- Projects where bundle size matters (~15KB framework)
- Apps requiring fine-grained reactivity
- When you want simplicity without JSX
- Projects targeting low-end devices
Critical Conventions
ALWAYS use regular functions, NOT arrow functions, for reactive components:
const MyComponent = function(ctx: Comp) {
const [count, setCount] = ctx.useState(0);
return div("Count: " + count);
};
const Broken = () => {
const [count, setCount] = ctx.useState(0);
return div(count);
};
Why? Regular functions get a state tree from Cradova's rendering system. Arrow functions don't receive ctx, making them non-reactive. This convention controls how many state objects exist in the DOM.
Quick Start
import { div, h1, button, Page, Router } from "cradova";
const Counter = function(ctx: Comp) {
const [count, setCount] = ctx.useState(0);
return div(
h1("Count: " + count),
button("Increment", {
onclick() { setCount(c => c + 1); }
})
);
};
const HomePage = new Page({
title: "My App",
template: function(ctx) { return Counter(ctx); }
});
Router.BrowserRoutes({
"/": HomePage
});
Core Concepts
State Management
- Signal - Global reactive state with pub/sub
- useState - Component-local state
- useEffect - Side effects and lifecycle
- useMemo / useCallback - Performance optimization
- useRef - DOM element references
Routing
- Page - Define pages with template, title, activation hooks
- Router.BrowserRoutes - Configure routes
- Router.navigate() - Programmatic navigation
- Lazy loading via dynamic imports
Control Flow
- $if - Conditional rendering
- $ifelse - If/else conditionals
- $switch/$case - Switch statement rendering
DOM Elements
- All standard HTML elements: div, p, button, h1-h6, img, input, etc.
- raw() - Inject raw HTML
- ref.bind("name") - Reference DOM elements
See Also