Use this as a concise reference when building Datastar-driven UI in this repo.
- Backend drives state; frontend is a projection of server truth.
- Patch elements and signals rather than manually mutating DOM.
- Use signals for user-driven, short-lived UI state.
- Signals are reactive variables prefixed with
$. - Signals can be created via:
data-bindon inputsdata-computedfor derived valuesdata-signalsto patch one or more signals
data-bind:fooordata-bind="foo": two-way bind input to$foo.data-text="$foo": set element text from a signal/expression.data-computed:bar="...": computed, read-only signal.data-show="expr": show/hide element based on expression.data-class:success="expr"ordata-class="{...}": conditional class list.data-attr:aria-hidden="expr"ordata-attr="{...}": bind attributes.data-signals:foo="1"ordata-signals="{...}": patch signals.data-on:click="...": bind events to expressions/actions.
application/jsonresponses are treated as “Patch Signals” events.text/event-streamresponses may includedatastar-patch-signalsSSE events.
text/htmlresponses patch DOM elements by ID using morphing.- SSE streams can emit
datastar-patch-elementsevents for live updates.
- Prefer
@get()/@post()actions for backend interaction. - Use
data-showwith initialstyle="display: none"to avoid flash. - Don’t manage browser history; use normal links and redirects.