Skip to content
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

Allow promise to be returned from 'add()' #1670

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a0647e4
Allow promise to be returned from 'add()'
dchambers Aug 17, 2017
184fd60
Merge branch 'master' into master
dchambers Aug 17, 2017
4bf6f8b
Merge branch 'master' into master
ndelangen Aug 18, 2017
c70fa3f
Merge branch 'master' into master
ndelangen Aug 18, 2017
b4b9ae8
Merge branch 'master' into master
Hypnosphi Aug 22, 2017
9d540aa
Merge branch 'master' into master
ndelangen Aug 22, 2017
ed514ef
Merge branch 'master' into master
dchambers Aug 22, 2017
02b307a
Document ability to wrap stories in promises
dchambers Aug 22, 2017
e06f2a9
Merge branch 'release/3.3' into master
ndelangen Aug 25, 2017
af0a7b6
Merge branch 'release/3.3' into master
ndelangen Sep 6, 2017
b7f2ed2
Merge branch 'release/3.3' into master
Hypnosphi Sep 6, 2017
1de3f22
Create CRA app for ES6-Promise kitchen sink
dchambers Sep 7, 2017
c94e1ec
Add Storybook to kitchen-sink
dchambers Sep 7, 2017
4dae5b5
Use storyshots to test the stories
dchambers Sep 7, 2017
b3e51bf
Make the `README.md` relevant for the kitchen-sink
dchambers Sep 7, 2017
49203b4
Wrap stories in promises
dchambers Sep 7, 2017
3ae6f4d
Update kitchen-sink to test code in this repo
dchambers Sep 7, 2017
52bbdaa
Merge branch 'release/3.3' into master
ndelangen Sep 7, 2017
220c2dc
Merge branch 'release/3.3' into master
Hypnosphi Sep 7, 2017
eb40517
Merge branch 'release/3.3' into master
ndelangen Sep 8, 2017
3fec2f4
ADD support for async components + decorators && ADD async render to …
ndelangen Sep 8, 2017
4fa1f0a
FIX documentation & CORRECT usage of async story
ndelangen Sep 8, 2017
eb658f1
DELETE redundant example
ndelangen Sep 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions docs/pages/basics/writing-stories/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
* * *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert these lines?, sorry, it's not your fault, the markdown linter needs a patch, But I haven't found the time to understand what changed/broke.


id: 'writing-stories'
title: 'Writing Stories'
---

## title: 'Writing Stories'

Storybook is all about writing stories. Usually a story contains a single state of one of your components. That's like a visual test case.

Expand Down Expand Up @@ -65,7 +66,7 @@ configure(loadStories, module);

Here we use Webpack's [require.context](https://webpack.github.io/docs/context.html#require-context) to load modules dynamically. Have a look at the relevant Webpack [docs](https://webpack.github.io/docs/context.html#require-context) to learn more about how to use require.context.

The **React Native** packager resolves all the imports at build-time, so it's not possible to load modules dynamically. If you don't want to import all your stories manually you can use [react-native-storybook-loader](https://github.com/elderfo/react-native-storybook-loader) to automatically create the import statements for all of your stories.
The **React Native** packager resolves all the imports at build-time, so it's not possible to load modules dynamically. If you don't want to import all your stories manually you can use [react-native-storybook-loader](https://github.com/elderfo/react-native-storybook-loader) to automatically create the import statements for all of your stories.

## Using Decorators

Expand Down Expand Up @@ -127,6 +128,28 @@ storiesOf('My App/Buttons/Emoji', module)
));
```

## Wrapping stories within promises

You may have components that only render themselves correctly once some data has arrived from a back-end (e.g. a mock back-end used for testing). While these components could be added synchronously, where a spinner could be displayed until the data arrives, you may prefer to delay rendering the component until the data is actually available.

If you happen to use the storyshot plug-in then the ability to wrap your story within a promise becomes even more useful, since otherwise your snapshots will only show the component's loading spinner rather than a component populated with data.

In this next example the data to be rendered is coming from a mock GraphQL back-end, but will only be rendered once that back-end is ready:

```js
import React from 'react';
import { storiesOf } from '@storybook/react';
import { ApolloProvider } from 'react-apollo'
import createClient from './mock-client';

storiesOf('My component', module)
.add('default state', createClient().then(client => () => (
<ApolloProvider client={client}>
<SomeComponent />
</ApolloProvider>
)));
```

## Run multiple storybooks

You can run multiple storybooks for different kinds of stories (or components). To do that, you can create different NPM scripts to start different stories. See:
Expand Down