Storybook Preact story rendering breaks when using hooks to declare state in stories
See original GitHub issueDescribe the bug
Using preact/hooks
inside of story functions breaks Storybook for Preact story rendering.
To Reproduce
The following story errors out:
import { h } from 'preact';
import { useState } from 'preact/hooks';
export default {
title: 'Sample story'
};
export const Bug = () => {
const [state, setState] = useState(false);
return (
<button onClick={() => setState(!state)}>{state ? 'true' : 'false'}</button>
);
}
If you declare state in another function as a functional component, the story works:
import { h } from 'preact';
import { useState } from 'preact/hooks';
export default {
title: 'Sample story'
};
const Template = () => {
const [state, setState] = useState(false);
return (
<button onClick={() => setState(!state)}>{state ? 'true' : 'false'}</button>
);
}
export const NoBug = () => <Template/>
Expected behavior There’s no clear indication in the documentation that that might not be allowed. It might be worth mentioning that somewhere in Writing Stories sections.
Screenshots N/A
Code snippets See above.
System
The npx sb@next info
command fails because of integrity checks, but I am using Storybook 6.1.17
.
"@storybook/addon-actions": "6.1.17",
"@storybook/addon-essentials": "6.1.17",
"@storybook/addon-links": "6.1.17",
"@storybook/preact": "6.1.17",
"storybook-addon-designs": "5.4.3",
"storybook-addon-themes": "6.0.1",
Additional context None.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Test runner Addon | Storybook: Frontend workshop for UI ...
The test runner is simple in design – it just visits each story from a running Storybook instance and makes sure the component...
Read more >Newest 'storybook-addon-specifications' Questions
Hi i am using storybook in react, For me i am facing issue in configuring firebase and state in storybook, Firebase is getting...
Read more >@storybook/core-events | Yarn - Package Manager
NOTE: For Angular users using inline story rendering in addon-docs, this is a breaking prerelease change. See below and apologies for the back...
Read more >storybookjs/storybook (Raised $170.00) - Issuehunt
[Bug]: Next.js 13 hook useSelectedLayoutSegment breaks storybook. Unfunded#20320created by ... MDX does not display the source snippet when using render.
Read more >Preact Signals and React's maintainers' view : r/reactjs - Reddit
Local state change to a component does not cause complete re-rendering of the hierarchy btw. So no memo needed. It only re-renders that ......
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 FreeTop 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
Top GitHub Comments
Ermahgerd!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-alpha.1 containing PR #14473 that references this issue. Upgrade today to the
@next
NPM tag to try it out!It looks like there’s a problem in the preact kitchen sink app. In
package.json
, we have:This installs
preact
as a dev dependency when bootstrapping, so whenclient/preview/render.tsx
imports thepreact
package, it would always importpreact^10.5.9
. If the app uses8.x
, the mismatch betweenVNode
types in8.x
and10.x
would explain why the kitchen sink app doesn’t work in development, since it uses8.x
. Upgrading preact to10.x
on the kitchen sink app would make it work.After fixing this problem, the next step will be solving the original hooks problem mentioned in this issue.