-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Adding stories from data structure throws error #112
Comments
Hi @shilman, const todoStories = storiesOf('TodoItem', module)
for (const key in data) {
todoStories.add(key, () => getItem(data[key]))
} React storybook can be modified to support data structures by changing these 2 lines.
But using a function to create the component can be useful. Let's keep the issue open for now. |
@mnmtanish You're correct, it's just a bug in my code, not a problem with storybook. Thanks for the quick response and solution! I think we can close the issue. |
You're welcome 😃 |
@mnmtanish Could be a convenience function perhaps, something like |
I was thinking this as well. The only problem though is that currently the Perhaps something like: todoStories.addAll(data, (props) => <TodoItem {...props} />); Where the render function of // functional component
const TodoItem = ({ id, text, completed }) => <div>{id}: {text} {completed ? 'Y' : 'N'}</div>;
// ... other set-up
// Since it would be called, given the props.
todoStories.addAll(data, TodoItem); |
I don't think anyone will stop you 😄 One thing I notice though is that |
Looking into the code it's a non-trivial change. I think it's better implemented as a convenience function external to the library. This works for me for now:
Though I guess this only works for functional components. Anybody know how to write a generic function to render a class-based component? |
Extend React Native versions range to 0.37
todoStories.addAll(data, TodoItem); #1209 Will be considered for api-v2 |
I have a working set of stories from the sample code. However, when I try to populate stories from a simple data structure, storybook gives me an error. Loading stories from data would keep code DRY when you are sharing fixture data between stories and unit tests.
When I modify the storybook example
components/stories/TodoItem.js
with the following trivial change, it gives me the following errorpreview.js?a230:61 Uncaught TypeError: story is not a function
. Is there a better way to do this?The text was updated successfully, but these errors were encountered: