datastar
Skill49 starsChanged 10 months agoMITView on GitHub
Guide for building interactive web UIs with Datastar and gomponents-datastar. Use this skill when adding frontend interactivity to Go web applications with Datastar attributes.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- MarcinDudekDev/claude-skill-datastartheir own version, first seen May 16, 2026
- danmestas/wardrobetheir own version, first seen Apr 30, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- danmestas/wardrobe★ 4same name
- MarcinDudekDev/claude-skill-datastar★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- address-code-reviewSkill
- autoresearchSkill
- blueskySkill
- brainstormSkill
- code-reviewSkill
- collaborationSkill
- decisionsSkill
- design-docSkill
- diarySkill
- gardenSkill
- gitSkill
- gomponentsSkill
- goSkill
- marimoSkill
- nanobananaSkill
- observable-plotSkill
- save-web-pageSkill
- sqlSkill
- worktreesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 13 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈13
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Use this skill when:
- Distinctive: line 21
Prerequisite: When using Datastar with Go, also use the gomponents skill for HTML component patterns.
- Very specific: line 56
Use dot-notation for nested signals: $user.name
- Distinctive: line 71
data-computed: - Create derived read-only signals:
- Distinctive: line 76
data-init: - Run expressions when element loads:
- Distinctive: line 131
data-on-interval: - Run at regular intervals:
- Distinctive: line 143
data-ref: - Create signal referencing DOM element:
- Distinctive: line 153
data-ignore-morph: - Keep Datastar active but skip morphing:
- Distinctive: line 209
datastar-patch-signals: - Update signal values:
- Distinctive: line 215
datastar-remove-elements: - Remove elements by selector:
- Distinctive: line 231
Use dot imports for a clean DSL:
- Distinctive: line 260
Computed: - Create computed signals (key-value pairs):
- Distinctive: line 265
Init: - Run expression on load:
- Distinctive: line 365
Use modifier constants with event functions:
- Very specific: line 486
Signal naming: Use $ prefix in expressions, not in Go code
- Very specific: line 487
Avoid conflicts: Use data.Text() for Datastar text binding, gomponents Text() for static content
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Datastar
Overview
Datastar is a lightweight frontend framework that enables backend-driven, interactive UIs through a hypermedia-first approach. It combines backend reactivity (similar to htmx) with frontend reactivity (like Alpine.js) using standard HTML data-* attributes.
When to Use This Skill
Use this skill when:
- Adding frontend interactivity to server-rendered HTML
- Building reactive UIs driven by backend state
- Using Datastar with gomponents in Go applications
- Working with Server-Sent Events (SSE) for real-time updates
Prerequisite: When using Datastar with Go, also use the gomponents skill for HTML component patterns.
Installation
Browser (CDN)
<script type="module" src="https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.0-RC.7/bundles/datastar.js"></script>Go (gomponents-datastar)
go get maragu.dev/gomponents-datastarPart 1: Datastar Fundamentals
Core Concepts
Signals
Signals are reactive state containers. When a signal's value changes, all dependent expressions automatically update.
<div data-signals="{count: 0}">
<span data-text="$count"></span>
<button data-on:click="$count++">Increment</button>
</div>- Signal names are prefixed with
$in expressions - Setting a signal to
nullorundefinedremoves it - Use dot-notation for nested signals:
$user.name
DOM Patching
Datastar uses morphing to update only changed DOM parts while preserving state. The backend sends HTML fragments that patch into the existing page.
Attributes Reference
State Management
data-signals - Initialize reactive signals:
<div data-signals="{name: 'World', count: 0}"></div>data-computed - Create derived read-only signals:
<div data-computed="{doubled: $count * 2}"></div>data-init - Run expressions when element loads:
<div data-init="console.log('Loaded')"></div>Data Binding
data-text - Bind text content to an expression:
<span data-text="'Hello, ' + $name"></span>data-bind - Two-way binding for form elements:
<input data-bind="$name" type="text">data-show - Conditionally show/hide elements:
<div data-show="$isVisible">Only shown when true</div>Styling
data-class - Conditionally apply CSS classes:
<div data-class="{'active': $isActive, 'error': $hasError}"></div>data-style - Set inline styles dynamically:
<div data-style="{'color': $textColor, 'opacity': $opacity}"></div>data-attr - Set HTML attributes dynamically:
<button data-attr="{'disabled': $isLoading}">Submit</button>Events
data-on - Attach event listeners:
<button data-on:click="$count++">Click me</button>
<input data-on:input="$search = evt.target.value">
<form data-on:submit__prevent="@post('/submit')">The evt variable references the event object.
data-on-intersect - Trigger when element enters viewport:
<div data-on-intersect="@get('/load-more')">Loading...</div>data-on-interval - Run at regular intervals:
<div data-on-interval="$elapsed++">Timer: <span data-text="$elapsed"></span></div>data-on-signal-patch - Execute when signals update:
<div data-on-signal-patch="console.log('Signals changed:', patch)"></div>DOM Control
data-ref - Create signal referencing DOM element:
<input data-ref="$inputEl" type="text">data-ignore - Exclude element from Datastar processing:
<div data-ignore>Third-party widget here</div>data-ignore-morph - Keep Datastar active but skip morphing:
<div data-ignore-morph>Preserve this DOM structure</div>data-preserve-attr - Preserve attributes during morphing:
<input data-preserve-attr="value" type="text">Backend Actions
@get(), @post(), @put(), @patch(), @delete() - Send requests to backend:
<button data-on:click="@get('/api/data')">Load</button>
<button data-on:click="@post('/api/submit')">Submit</button>Modifiers
Modifiers extend attribute behavior using double-underscore syntax:
Timing Modifiers
__debounce/__debounce_500ms- Debounce execution__throttle/__throttle_1s- Throttle execution__delay/__delay_200ms- Delay execution
Event Modifiers
__prevent- CallpreventDefault()__stop- CallstopPropagation()__capture- Use capture phase__passive- Mark as passive listener__once- Execute only once__self- Only trigger if target is the element itself__outside- Trigger when event occurs outside element__window- Attach listener to window
Example with Modifiers
<input data-on:input__debounce_300ms="@get('/search?q=' + $query)">
<button data-on:click__once="@post('/track-click')">Track</button>
<form data-on:submit__prevent="@post('/submit')">Server-Sent Events (SSE)
Datastar uses SSE for streaming responses. The backend sends events with text/event-stream content type.
SSE Event Types
datastar-patch-elements - Patch HTML into the DOM:
event: datastar-patch-elements
data: elements <div id="content">Updated content</div>datastar-patch-signals - Update signal values:
event: datastar-patch-signals
data: signals {count: 42}datastar-remove-elements - Remove elements by selector:
event: datastar-remove-elements
data: selector #old-elementPart 2: gomponents-datastar
Overview
gomponents-datastar provides Go functions that generate Datastar attributes as gomponents nodes. It integrates seamlessly with the gomponents library.
Import Convention
Use dot imports for a clean DSL:
import (
. "maragu.dev/gomponents"
. "maragu.dev/gomponents/html"
data "maragu.dev/gomponents-datastar"
)Note: The data alias is recommended for datastar.
For up-to-date API documentation, run:
go doc maragu.dev/gomponents-datastarFunction Reference
State Management
Signals - Initialize reactive signals:
data.Signals(map[string]any{
"count": 0,
"name": "World",
})Computed - Create computed signals (key-value pairs):
data.Computed("doubled", "$count * 2")Init - Run expression on load:
data.Init("console.log('Component loaded')")Data Binding
Text - Bind text content:
Span(data.Text("'Hello, ' + $name"))Bind - Two-way form binding:
Input(Type("text"), data.Bind("$name"))Show - Conditional visibility:
Div(data.Show("$isVisible"), Text("Shown when visible"))Styling
Class - Conditional classes (key-value pairs):
data.Class("active", "$isActive", "error", "$hasError")Style - Dynamic inline styles (key-value pairs):
data.Style("color", "$textColor", "opacity", "$opacity")Attr - Dynamic attributes (key-value pairs):
data.Attr("disabled", "$isLoading", "aria-busy", "$isLoading")Events
On - Attach event listeners:
data.On("click", "$count++")
data.On("click", "@post('/submit')", data.ModifierPrevent)
data.On("input", "$search = evt.target.value", data.ModifierDebounce)OnIntersect - Viewport intersection:
data.OnIntersect("@get('/load-more')")OnInterval - Periodic execution:
data.OnInterval("$elapsed++")OnSignalPatch - React to signal changes:
data.OnSignalPatch("console.log('Updated')")DOM Control
Ref - Reference DOM element:
data.Ref("$inputEl")Ignore - Skip Datastar processing:
data.Ignore()IgnoreMorph - Skip morphing only:
data.IgnoreMorph()PreserveAttr - Preserve attributes during morph:
data.PreserveAttr("value", "checked")Request Helpers
Indicator - Show loading state:
data.Indicator("$isLoading")JSONSignals - Control which signals are sent:
data.JSONSignals(data.Filter{Include: "form.*"})
data.JSONSignals(data.Filter{Exclude: "internal.*"})Modifiers
Use modifier constants with event functions:
// Timing
data.ModifierDebounce // __debounce
data.ModifierThrottle // __throttle
data.ModifierDelay // __delay
// Event behavior
data.ModifierPrevent // __prevent
data.ModifierStop // __stop
data.ModifierCapture // __capture
data.ModifierPassive // __passive
data.ModifierOnce // __once
data.ModifierSelf // __self
data.ModifierOutside // __outside
data.ModifierWindow // __window
// Duration/threshold helpers
data.Duration(500 * time.Millisecond) // __500ms
data.Threshold(0.5) // __threshold_0.5Complete Example
package views
import (
"net/http"
. "maragu.dev/gomponents"
. "maragu.dev/gomponents/html"
ghttp "maragu.dev/gomponents/http"
ds "maragu.dev/gomponents-datastar"
)
func CounterPage() Node {
return HTML5(HTML5Props{
Title: "Counter",
Language: "en",
Head: []Node{
Script(
Type("module"),
Src("https://cdn.jsdelivr.net/gh/starfederation/[email protected]/bundles/datastar.js"),
),
},
Body: []Node{
Div(
data.Signals(map[string]any{"count": 0}),
H1(data.Text("'Count: ' + $count")),
Button(
data.On("click", "$count++"),
Text("Increment"),
),
Button(
data.On("click", "$count--"),
Text("Decrement"),
),
Button(
data.On("click", "@post('/api/save')"),
Text("Save to Server"),
),
),
},
})
}
func SearchForm() Node {
return Form(
data.Signals(map[string]any{"query": "", "results": []any{}}),
data.On("submit", "@get('/search?q=' + $query)", data.ModifierPrevent),
Input(
Type("text"),
data.Bind("$query"),
data.On("input", "@get('/search?q=' + $query)", data.ModifierDebounce, data.Duration(300*time.Millisecond)),
Placeholder("Search..."),
),
Div(
ID("results"),
data.Show("$results.length > 0"),
data.Text("'Found ' + $results.length + ' results'"),
),
)
}SSE Handler Pattern
func handleSSE(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
flusher, ok := w.(http.Flusher)
if !ok {
http.Error(w, "SSE not supported", http.StatusInternalServerError)
return
}
// Patch HTML elements
fmt.Fprintf(w, "event: datastar-patch-elements\n")
fmt.Fprintf(w, "data: elements <div id=\"content\">Updated!</div>\n\n")
flusher.Flush()
// Update signals
fmt.Fprintf(w, "event: datastar-patch-signals\n")
fmt.Fprintf(w, "data: signals {\"count\": 42}\n\n")
flusher.Flush()
}Tips
- Signal naming: Use
$prefix in expressions, not in Go code - Avoid conflicts: Use
data.Text()for Datastar text binding, gomponentsText()for static content - Modifiers: Chain multiple modifiers:
data.On("click", "...", data.ModifierPrevent, data.ModifierOnce) - SSE IDs: Elements patched via SSE need matching
idattributes - Morphing: Datastar preserves form input state during DOM updates by default
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

