-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@storybook/html - can't run JS in story #7786
Comments
@whoisryosuke Super hacky and I'm sure there's a better solution, but have you tried a setTimeout just to see if it works? @ndelangen we have APIs for registering for channel events. Are they accessible when I'm writing a story? |
This probably means that
|
@Hypnosphi this is really awesome ❤️ |
@shilman unfortunately, it doesn't work yet: the effects are triggered too early. I'll send a PR shortly |
Yowza!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.0-beta.36 containing PR #7791 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Hi @Hypnosphi @ndelangen what's today's state of documentation for Storybook hooks? I see https://storybook.js.org/docs/addons/api/#storybook-hooks exists, but Algolia search on website finds no matches for "useEffect". I tested it, and it seems to work exactly as needed. How come the docs missing on it? |
Unfortunately, the docs only exist in form of inline comments: https://github.com/storybookjs/storybook/blob/next/lib/addons/src/hooks.ts#L279 |
@lkraav a PR on the docs would be super super useful, maybe you'd be able to contribute? |
In a 1 month time horizon yes. Within the next 2 weeks, probably not. Main barrier is learning what the current practices and setup for docs here is, and figuring out what exactly to write. Brainspace is extremely limited due to an ongoing project. |
I worked around this simply by using jQuery's document ready function.
|
Any chance someone could provide an example of how the Even with having all of my logic for my demo in a separate |
Now I'm just using {
...otherStuffs,
render: () => {
// Create DOM element
const ele = document.createElement('div');
setTimeout(() => {
// Do anything to your element's been created before
})
return ele.innerHTML;
}
} |
I think y'all might be interested to learn about the storybook play function: |
Describe the bug
Can't run JS functions alongside HTML of story.
I need to run a jQuery function once the page loads, and none of the methods (using Event Listeners and
DOMContentLoaded
) I've discovered seem to work.To Reproduce
or more complex example using a Mutation Observer:
Expected behavior
Runs JS on story load and when content changes.
Code snippets
see above
System:
Environment Info:
System:
OS: macOS 10.14
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Binaries:
Node: 8.12.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Browsers:
Chrome: 76.0.3809.100
Firefox: 61.0.2
Safari: 12.0
npmPackages:
@storybook/addon-a11y: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-actions: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-backgrounds: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-centered: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-events: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-jest: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-knobs: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-links: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-notes: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-options: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-storyshots: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-storysource: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addon-viewport: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/addons: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/core: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/core-events: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/html: 5.2.0-alpha.35 => 5.2.0-alpha.35
@storybook/source-loader: 5.2.0-alpha.35 => 5.2.0-alpha.35
Additional context
storybook.config.js
.The text was updated successfully, but these errors were encountered: