Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Automatically increments counter every second.
<div data-controller="counter" data-counter-count-value="0">
<h2>Counter: <span data-counter-target="count">0</span></h2>
</div>
<script>
import { Application } from '@hotwired/stimulus';
const application = Application.start();
application.register('counter', class extends Stimulus.Controller {
static targets = ['count'];
static values = { count: Number };
connect() { this.interval = setInterval(()=>{ this.countValue++; this.updateDisplay(); },1000); }
disconnectedCallback() { clearInterval(this.interval); }
updateDisplay() { this.countTarget.textContent = this.countValue; }
});
</script>Stimulus.js is a modest JavaScript framework designed to enhance static HTML by connecting elements to JavaScript controllers. It complements server-rendered HTML, making it ideal for modestly interactive UIs without a heavy frontend framework.
Origin & Creator
Created by Basecamp (David Heinemeier Hansson and team) and first released in 2016.
Industrial Note
Stimulus is perfect for server-rendered applications that need modest interactivity, like Rails apps, Turbo-driven frontends, and progressive enhancement use-cases.