⚠️ This lesson is retired and might contain outdated information.

Stimulus in 60 Seconds

Rodrigo Pombo
InstructorRodrigo Pombo
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

Learn Stimulus fast. This is a quick overview of how to use Stimulus core features compressed into one minute. Remember to pause the video if you need time to understand something!

This lesson uses Stimulus v2.

To learn more about Stimulus and the rest of the features we haven't covered, visit the official website.

Rodrigo Pombo: [0:00] To make a piece of HTML interactive, you need to create a controller class and link an element to the controller with the data-controller attribute. You can use the data-action attribute, for example, to handle click events. Specifying the name of the controller and the method, Stimulus will call the method on every click.

[0:20] To add a state, you can add a property to the controller to display it. First, you need a reference to a DOM element. Stimulus calls those references targets. After you define the target, you can access the DOM element as a controller property. Now every time the state changes, Stimulus re-renders the component.

[0:45] To have two of these buttons, you can duplicate the HTML and reuse the controller. If you add an attribute and apply it as a value in the controller, you can access it as a controller property similar to targets.

egghead
egghead
~ 13 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today