Askr
Getting Started

First Application

Use first application with the current published Askr packages.

  • @askrjs/askr0.0.59

How to use first application

Start with this complete first application shape, then replace the example data and application service with your own.

  1. Import the published @askrjs/askr entrypoint.
  2. Keep first application configuration next to the component, route, or server composition root that owns it.
  3. Handle pending, unavailable, cancellation, and failure states, then verify the production path.
import { state } from '@askrjs/askr';
import { createRouteRegistry, route } from '@askrjs/askr/router';

function HomePage() {
  const count = state(0);
  return <button onClick={() => count.set(count() + 1)}>Count: {count()}</button>;
}

export const registry = createRouteRegistry(() => route('/', HomePage));

Create the project

Run `askr create spa my-app` (or another template) and `cd my-app`. Open the generated route registry file — typically `src/pages/**/_routes.tsx` — to see how the starter route is already wired up with `route()`.

Register a route

Routes are declared with `route(path, Component, options?)` inside a `registerRoutes()` call, or captured explicitly with `createRouteRegistry()`. Add a new entry — `route('/about', () => <About />)` — inside the existing `registerRoutes(() => { ... })` block, then confirm `getManifest()` or the registry you pass to `createSPA` picks it up.

Add state

Call `state(initialValue)` inside a component to get a `[getter, setter]` pair — read the current value by calling the getter as a function, and update it by calling the setter, e.g. `setCount((value) => value + 1)`. State reads are tracked automatically wherever they're called, so a component re-renders when the state it read changes.

Build the application

Run `npm run build` from the generated project; for SPA and full-stack templates this produces a client bundle, and for SSG it can drive `createStaticGen()` to render every route to HTML in `outputDir`. Check the build output against the application mode you picked — an SSG build should produce static files per route, while an SSR build produces a server bundle you run with Node.