-
-
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
Component with react router #769
Comments
You should wrap your story in a storiesOf('Logo', module)
.addDecorator(story => (
<MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
))
.add('normal', () => <Logo />) You can read a full example here: https://blog.hichroma.com/graphql-react-tutorial-part-5-6-ac36b6962a8a |
See this comment here if you want links to fire Storybook actions: #485 (comment) |
Was searching for this error, and had a hard time finding this issue because it was posted in an image. Pasting the text now to make it easier for people to find in the future:
|
I get the error below while using Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
at invariant (http://localhost:6006/static/preview.bundle.js:2056:15)
at createFiberFromElementType (http://localhost:6006/static/preview.bundle.js:27773:5)
at createFiberFromElement (http://localhost:6006/static/preview.bundle.js:27718:15)
at reconcileSingleElement (http://localhost:6006/static/preview.bundle.js:28966:19)
at reconcileChildFibers (http://localhost:6006/static/preview.bundle.js:29065:35)
at reconcileChildrenAtPriority (http://localhost:6006/static/preview.bundle.js:29715:30)
at reconcileChildren (http://localhost:6006/static/preview.bundle.js:29706:5)
at finishClassComponent (http://localhost:6006/static/preview.bundle.js:29842:5)
at updateClassComponent (http://localhost:6006/static/preview.bundle.js:29814:12)
at beginWork (http://localhost:6006/static/preview.bundle.js:30193:16) Any ideas what might be going on? |
Hello @oyeanuj, |
@aperkaz I couldn't get this to work yet, so not including those components in Storybook :( I'll wait for a solution as well.. |
You may want to check what version of react router you're using. The solution by @shilman above works with react router 4.1.1 and @storybook/react v 3.3.8 |
For react-router 3: // ...
import { Router, Route } from 'react-router';
import createMemoryHistory from 'react-router/lib/createMemoryHistory';
storiesOf('Foo', module)
.addDecorator(story => (
<Router history={createMemoryHistory('/')}>
<Route path="/" component={() => story()} />
</Router>
))
.add('Default', () => <Foo />); |
Accetped answer works great, but I get
Any help with this error |
Add code from this link: [storybookjs/storybook#769]
For anyone landing here in future after googling and tearing out hair, allow me to maybe save you some time. The project I was working on had a version mismatch between This caused an issue in my case due to React changing the way I fixed it by switching |
For anybody else what actually helped me was this package: https://github.com/gvaldambrini/storybook-router/ |
Thanks so much, the responses helped |
For anyone using hooks:
|
How can i use storybook with components wich uses react router
Component example
Error
The text was updated successfully, but these errors were encountered: