Observe Component Behavior with Actions Addon

Michael Chan
InstructorMichael Chan
Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated 2 months ago

Gain unparalleled insight into component behavior with the Storybook Actions Addon. Learn to log every click, hover, and focus event, providing a clear window into real-time component responses.

[00:00] We've all added console dot log statements to validate our component interfaces. With Storybook actions, that's a thing of the past. To see these actions, make sure that your add ons panel is enabled, then click on the actions tab. In these sample stories, you can just click this button and everything will get logged. Now this doesn't just work for on [00:20] click common events. Jump to header and you'll see it work with custom events as well logging on log out for this logged in story and on log in for this logged out story as well as on create account. So what's making all of this work? It's a file inside of the hidden dot [00:39] storybook directory under the name preview. Preview is a module that controls all of these stories in storybook. In here, we have configuration to look for any on prefixed event using a regex and log out the event that happened. If we disable this high level observer and click on our [00:59] buttons again, we'll see that they no longer log anything. Now this is a fairly advanced setup. I'll show you a way to do this closer to the component, but I wanna show you how to disable this in case you don't wanna see some on prefixed events. In general, this is a great way to prevent extraneous logging statements that [01:18] somehow always find their way into production code.

egghead
egghead

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