Built-in Components

Components that come with JAF.

No imports needed.

Show

Conditional rendering with fallback.

source
<Show when={user} fallback="<p>Not logged in</p>">
  <p>Welcome, {user.name}!</p>
</Show>

<Show when={item} keyed>
  <ItemDetail item={item} />
</Show>
PropTypeDescription
whenanyCondition (truthy shows children)
fallbackstringLiteral HTML when falsy. An expression in it is a build error
keyedbooleanRe-render on reference change

Full documentation →

For

Declarative list iteration.

source
<For each={items} as="item" key="id" fallback="<p>Empty</p>">
  <li>{item.name}</li>
</For>

<For each={items} as="item" index="i">
  <li>{i}: {item}</li>
</For>
PropTypeDescription
eacharrayArray to iterate
asstringItem variable name
indexstringIndex variable name
keystringProperty for keying
fallbackstringHTML when empty. The one fallback whose expressions are compiled

Full documentation →

Switch / Match

Multi-branch conditionals.

source
<Switch fallback="<p>Unknown</p>">
  <Match when={status === 'loading'}><Spinner /></Match>
  <Match when={status === 'error'}><Error /></Match>
  <Match when={status === 'success'}><Content /></Match>
</Switch>
Switch PropsTypeDescription
fallbackstringLiteral HTML when no match. An expression in it is a build error
Match PropsTypeDescription
whenanyCondition (truthy renders)

Full documentation →

Dynamic

Render elements/components dynamically.

source
<Dynamic is="button" class="btn">Click</Dynamic>
<Dynamic is={href ? 'a' : 'button'} href={href}>Action</Dynamic>
<Dynamic is="UserCard" user={user} />
PropTypeDescription
isstringTag name or component name
...restanyPassed to element/component

Full documentation →

Teleport

Render in different DOM location.

source
<Teleport to="body">
  <Modal />
</Teleport>

<Teleport to="#modals" disabled={isMobile}>
  <Dropdown />
</Teleport>
PropTypeDescription
tostringCSS selector target
disabledbooleanRender in place if true

Full documentation →

Suspense

Show fallback while lazy components load.

source
<Suspense fallback="<p>Loading...</p>">
  <LazyComponent />
</Suspense>
PropTypeDescription
fallbackstringLiteral HTML while loading. A component tag or an expression in it is a build error

Full documentation →

ErrorBoundary

Catch errors and show fallback.

source
<ErrorBoundary fallback="<p>Something went wrong</p>">
  <RiskyComponent />
</ErrorBoundary>
PropTypeDescription
fallbackstringLiteral HTML on error. A component tag or an expression in it is a build error

Full documentation →

Guard

Protect content with permissions.

source
<Guard access="admins" redirect="/login">
  <AdminPanel />
</Guard>

<Guard access={isLoggedIn}>
  <Dashboard />
</Guard>

<Guard access={["admins", "editors"]}>
  <StaffArea />
</Guard>
PropTypeDescription
accessstring | array | booleanPermission check
redirectstringA literal path to navigate to when denied. Omitted, it falls to guards.redirect in config, then /

Full documentation →

Layout

Extend parent layout (use in nested layout.html).

source
<!-- pages/admin/layout.html -->
<Layout>
  <Sidebar />
  <slot />
</Layout>

Full documentation →

slot

Content projection placeholder.

source
<!-- Default slot -->
<slot />
<slot>Default content</slot>

<!-- Named slot -->
<slot name="header" />
<slot name="footer">Default footer</slot>

Full documentation →