Language

Components, props, and setup

Keep imports, typed public props, module code, local components, and Octane hooks together.

source

A component may have one props declaration. Its contents become the complete typed function parameter in generated TSRX.

UserCard.btsxbtsx
import type { User } from "./types.ts";props { user, compact = false }: { user: User; compact?: boolean } article.user-card(class={compact ? "compact" : ""})  h2 #{user.name}

Setup emits TypeScript inside the component body before its template root. Use it for local values and Octane hooks.

Counter.btsxbtsx
import { useMemo, useState } from "octane";props { initialCount }: { initialCount: number }setup const [count, setCount] = useState(initialCount);setup const doubled = useMemo(() => count * 2); button(onClick={() => setCount(count + 1)})  | Count: #{count}, doubled: #{doubled}

Module declarations emit TypeScript at module scope. Use them for directives, types, context values, constants, and helper functions.

Theme.btsxbtsx
module  "use strong";  const shortcutKey = "/"; import { useEffect } from "octane";

A component declaration creates a tagless local component using the same BTSX syntax as the default export.

ThemeLabel.btsxbtsx
component ThemeLabel  setup const currentTheme = use(Theme);  p Current theme: #{currentTheme} Theme.Provider(value={theme})  ThemeLabel