question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can not use jsx in decorators in preview.js

See original GitHub issue

in 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:open
  • Created 2 years ago
  • Reactions:11
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
Dreamuforcommented, Jan 16, 2022

Hi, I encounter the same issue, and I used React.createElement to solve the problem.

Before:

export const decorators = [
  (Story) => (
    <ThemeProvider theme="default">
      <Story />
    </ThemeProvider>
  ),
];

Solutions:

export const decorators = [
  (Story) => {
    return React.createElement(ThemeProvider, {
      children: React.createElement(Story),
    });
  },
];

Hope this helps! @farshidinanloo

3reactions
vanyadymouskycommented, Sep 28, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found