I'm working with Storybook for components creation in pure HTML, CSS and JS (jQuery actually).
I'm wondering if there's a callback function when a story is rendered on the screen (like useEffect
for React) because I need to run then the relative jQuery code only when the component is really in the DOM.
Here's my situation:
// Button.stories.js
// my pure HTML component
const Button = () => `<button>My button </button>`;
export default {
title: 'Buttons',
};
export const ButtonStory = () => Button()
// would be great something like: ButtonStory.callback = function(){ do this}
There's something without workaround? (Like wrap the HTML component inside react component and use useEffect for trigger the code)
Thanks
I'll share a not optimal solution I've found but maybe could be useful for others:
MyStory.stories.js
customRenderStory.js
In this way, I can execute the code inside
controller.js
each time the story is rendered. I need a timeout (which can be configured) because I can't be sure that the component will be mounted after the code execution.In my case, StoryBook in plain HTML and jQuery, seems is working.