š Actions don't work on non-`onClick` functions
See original GitHub issueDescribe the bug
Actions donāt work on non-onClick functions when a default value is defined in the component.
To Reproduce Steps to reproduce the behavior:
- Setup a create-react-app project with
sb init - Edit the
Button(and its prop types) to useonClick2:
export const Button = ({
onClick2 = Function.prototype,
}) => (
<button
onClick={onClick2}
type="button"
>
Hello
</button>
)
- Click on the
Buttonin Storybook, actions wonāt show.
I first noticed this with onChange and onSubmit; both which had default values.
Expected behavior I expect to see actions logged when I click the button.
Screenshots
Working:

Not working:

Code snippets
export const Button = ({
onClick2 = Function.prototype,
}) => (
<button
onClick={onClick2}
type="button"
>
Hello
</button>
)
System I deleted the clean project I made to for testing, but Iāve seen the issue in my existing project as well:
Environment Info:
System:
OS: Windows 10 10.0.19042
CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
Binaries:
Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 89.0.4389.90
Edge: Spartan (44.19041.423.0), Chromium (89.0.774.57)
npmPackages:
@storybook/addon-actions: ^6.1.21 => 6.1.21
@storybook/addon-controls: ^6.1.21 => 6.1.21
@storybook/addon-essentials: ^6.1.21 => 6.1.21
@storybook/addon-links: ^6.1.21 => 6.1.21
@storybook/node-logger: ^6.1.21 => 6.1.21
@storybook/react: ^6.1.21 => 6.1.21
Additional context
defaultProps is deprecated (https://github.com/facebook/react/pull/16210).
I donāt want to have to depend on it for default values even though I think itās superior to defining ECMAScript default values.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
JavaScript button onclick not working - Stack Overflow
Now the alert comes when I load the page not when I click on the button. ā Martin W Ā· I've mistaken the...
Read more >React onClick event handlers: A complete guide
Learn the basics of React's onClick event handler, including event listening, onClick buttons, synthetic events, custom events, and more.
Read more >Introduction to events - Learn web development | MDN
Events are actions or occurrences that happen in the system you are programming, which the system tells you about so your code can...
Read more >Button onclick event not working - JavaScript - SitePoint Forums
Okay, thanks! It takes care of the onclick event problem but I don't get any error messages but I should.
Read more >Making actions keyboard accessible by using the onclick ...
htm. Dostuff.htm must provide the same functionality as the script.The "return false;" at the end of the doStuff() event handling function tells theĀ ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Whatās happening here is that the actions addon is scanning through the existing argTypes and looking for function argTypes whose names matches the regex. When it fails, itās because those argTypes donāt exist or because they are not of type function. Perhaps we need to update the design to make it less finicky. Suggestions welcome!!
@Sawtaytoes youāre not binding the
onClick2handler in your story. When I fix that, it works as expected: