-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expecting a react element from stories for global IntlProvider decorator #1240
Comments
Can we see the code for the |
I don't have it at hand, but the code looks like this: import React from 'react';
import { FormattedMessage } from 'react-intl';
const Loading = () => {
return (
<div>
<FormattedMessage id='loading' defaultMessage='Loading...' />
<div className='spinner' />
<div>
)
}
export default Loading The import React from 'react';
import { configure, setAddon } from '@storybook/react';
import infoAddon from '@storybook/addon-info';
// add info addon
setAddon(infoAddon);
//stories loader
const req = require.context('../src', true, /\.stories\.js$/)
function loadStories() {
req.keys().forEach((filename) => req(filename))
}
// Run storybook
configure(loadStories, module); And my Loading.storybook.js like this: import React from 'react';
import { storiesOf } from '@storybook/react';
import Loading from '../components/Loading';
import { IntlProvider } from 'react-intl';
import '../styles/compiled-css/style.css';
import '../index.css';
const DEFAULT_LOCALE = 'en';
const DEFAULT_MESSAGES = require('../translations/locales/en')
storiesOf('Loading', module)
.add('default', () => (
<IntlProvider locale={DEFAULT_LOCALE} key={DEFAULT_LOCALE} messages={DEFAULT_MESSAGES}>
<Loading />
</IntlProvider>
)); Then the Loading component is also working without errors within storybook. |
Still don't know why it wasn't working with the decorator, but as storybook-addon-intl was updated to support stoybook v3 I don't need the workaround with the decorator anymore. |
@sthuber90 glad you got it fixed! 👍 |
You do not return value from anonymous function
to (curly braces => round braces)
It works for me |
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:
The component I try to test / start with is Loading.storybook.js:
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.
The text was updated successfully, but these errors were encountered: