-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
Description
Hello,
I would like to use storybook for a component of mine which uses react-intl. Preferably I would use the storybook-addon-intl for that matter, which unfortunately doesn't seem to support the current version of storybook yet. So to be able to use storybook nonetheless I edited .storybook/config.js to:
import React from 'react';
import { configure, setAddon, addDecorator } from '@storybook/react';
import infoAddon from '@storybook/addon-info';
import { IntlProvider } from 'react-intl';
// add info addon
setAddon(infoAddon);
// add a decorator to wrap stories rendering into IntlProvider
const DEFAULT_LOCALE = 'en';
const DEFAULT_MESSAGES = require('../src/translations/locales/en')
addDecorator(story => {
<IntlProvider locale={DEFAULT_LOCALE} key={DEFAULT_LOCALE} messages={DEFAULT_MESSAGES}>
{ story() }
</IntlProvider>
})
//stories loader
const req = require.context('../src', true, /\.stories\.js$/)
function loadStories() {
req.keys().forEach((filename) => req(filename))
}
// Run storybook
configure(loadStories, module);
The component I try to test / start with is Loading.storybook.js:
import React from 'react';
import { storiesOf } from '@storybook/react';
import Loading from '../components/Loading';
import '../styles/compiled-css/style.css';
import '../index.css';
//add a decorator to wrap stories rendering into IntlProvider
const DEFAULT_LOCALE = 'en';
const DEFAULT_MESSAGES = require('../translations/locales/en')
storiesOf('Loading', module)
.add('default', () => (
<Loading />
));
Unfortunately when running storybook I keep getting the error Expecting a react element for the story: "default" from "Loading".
Any idea why this is happening? I also reinstalled node_modules and checked that I don't use any storybook addon with old dependencies.