- Website: https://stimulusjs.org/
 - GitHub repo: https://github.com/stimulusjs/stimulus
 - Handbook: https://stimulusjs.org/handbook/introduction
 - Discourse: https://discourse.stimulusjs.org/
 
initialize: once, when the controller is first instantiatedconnect: anytime the controller is connected to the DOMdisconnect: anytime the controller is disconnected from the DOM
The data-action value click->hello#greet is called an action descriptor. This particular descriptor says:
clickis the event namehellois the controller identifiergreetis the name of the method to invoke
Stimulus defines click as the default event for actions on <button> elements. Certain other elements have default events, too. Here’s the full list:
a>clickbutton>clickform>submitinput>changeinput>type=submit clickselect>changetextarea>change
The data-target value hello.name is called a target descriptor. This particular descriptor says:
hellois the controller identifiernameis the target name
When Stimulus loads your controller class, it looks for target name strings in a static array called targets. For each target name in the array, Stimulus adds three new properties to your controller. Here, our source target name becomes the following properties:
this.sourceTargetevaluates to the first source target in your controller’s scope. If there is no source target, accessing the property throws an error.this.sourceTargetsevaluates to an array of all source targets in the controller’s scope.this.hasSourceTargetevaluates to true if there is a source target or false if not.
Each Stimulus controller has a this.data object with has(), get(), and set() methods. These methods provide convenient access to data attributes on the controller’s element, scoped by the controller’s identifier.
For example, in our controller above:
this.data.has("index")returns true if the controller’s element has a data-slideshow-index attributethis.data.get("index")returns the string value of the element’s data-slideshow-index attributethis.data.set("index", index)sets the element’s data-slideshow-index attribute to the string value of index
If your attribute name consists of more than one word, reference it as camelCase in JavaScript and attribute-case in HTML. For example, you can read the data-slideshow-current-class-name attribute with this.data.get("currentClassName").
e.g. <div data-controller="ControllerName">
e.g. <input data-target="ControllerName.TargetName">
e.g. <button data-action="eventName->ControllerName#methodName">Click me</button>
import { Controller } from "stimulus"
export default class extends Controller {
  static targets = []
  // or
  static get targets () {
    return []
  }
  
  initialize () {}
  connect () {}
  
  disconnect () {}
}Example HTML from the Stimulus home page
<div data-controller="hello">
  <input data-target="hello.name" type="text">
  <button data-action="click->hello#greet">
    Greet
  </button>
  <span data-target="hello.output">
  </span>
</div>