can not use jsx in decorators in preview.js
See original GitHub issuein react-boilerplate with storybook when try to add this decorator
export const decorators = [
(Story) => (
<div>
<Story />
</div>
)
];
it shows this error:
ERROR in ./.storybook/preview.js
Module build failed (from ./node_modules/@storybook/builder-webpack4/node_modules/babel-loader/lib/index.js):
SyntaxError:...\.storybook\preview.js: Unexpected token, expected "</>/<=/>=" (21:13)
19 | (Story) => (
20 | <div>
> 21 | <Story />
| ^
22 | </div>
23 | )
24 | ];
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Using useState along with global decorators throws error ...
When I use decorators along with useState in my components, I get, Storybook preview hooks can only be called inside decorators and story ......
Read more >stories.preview.(jsx,tsx,js,ts)
This file is an ES module that applies to all stories. You can control the way stories are rendered and add global decorators,...
Read more >Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >Storybook Configuration With CRA and TypeScript
js. To control the way stories are rendered and add global decorators and parameters, create a .storybook/preview.js file. This is loaded ...
Read more >Storybook Decorators for Angular
A decorator in Storybook is a function that can modify a story's HTML, ... main.js manager.js preview.js tsconfig.json. You may not have all ......
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
Hi, I encounter the same issue, and I used React.createElement to solve the problem.
Before:
Solutions:
Hope this helps! @farshidinanloo
@farshidinanloo Yes, it was about renaming decorators file preview.js to preview.tsx so jsx is now parsed correctly. Looks like I’m forced to do that since I’ve updated to 6.3.8 - in a case somebody hit same issue.