Adding stories from data structure throws error
See original GitHub issueI 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 error preview.js?a230:61 Uncaught TypeError: story is not a function
. Is there a better way to do this?
const data = {
'not completed': { id: 'the-id', text: 'Hello Todo', completed: false },
'completed': { id: 'the-id', text: 'Hello Todo', completed: true }
}
const todoStories = storiesOf('TodoItem', module)
for (const key in data) {
todoStories.add(key, getItem(data[key]))
}
// storiesOf('TodoItem', module)
// .add('not completed', () => {
// const todo = {
// id: 'the-id',
// text: 'Hello Todo',
// completed: false
// };
//
// return getItem(todo);
// })
// .add('completed', () => {
// const todo = {
// id: 'the-id',
// text: 'Hello Todo',
// completed: true
// };
//
// return getItem(todo);
// });
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Adding stories from data structure throws error · Issue #112
I have a working set of stories from the sample code. However, when I try to populate stories from a simple data structure,...
Read more >Error when trying to add data to vector inside structure
I am trying to add some data from a . txt file into a vector which is inside a structure, but the vector...
Read more >Handling operation errors - Apollo GraphQL Docs
By default, Apollo Client throws away partial data and populates the error.graphQLErrors array of your useQuery call (or whichever hook you're using).
Read more >Saving Data | Firebase Realtime Database - Google
Ways to Save Data ; push, Add to a list of data in the database. Every time you push a new node onto...
Read more >How to Add Extra Information to Errors in Go - DigitalOcean
One feature is the ability to wrap errors using the fmt.Errorf function with an error value that can be unwrapped later to access...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @shilman, I believe the code given above will work fine if we use an arrow function.
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.
I was thinking this as well. The only problem though is that currently the
add()
story requires you to pass a function that does the rendering.addAll
could only work like you’ve described if a Story was set-up knowing what component it would render, and then only allowed you to passprops
.Perhaps something like:
Where the render function of
addAll
passes the props each time. Could actually work quite well with functional components: