Skip to content

Commit 1192682

Browse files
committed
added simpler example for AsyncState
1 parent 47b3656 commit 1192682

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

docs/api/mixins/AsyncState.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,34 @@ When testing, use the `initialAsyncState` prop to simulate asynchronous
4040
data fetching. When this prop is present, no attempt is made to retrieve
4141
additional state via `getInitialAsyncState`.
4242

43-
Example
44-
-------
43+
Examples
44+
--------
45+
46+
In it simplest form, just return a hash of promises, they become state:
47+
48+
```js
49+
var User = React.createClass({
50+
mixins: [ Router.AsyncState ],
51+
52+
statics: {
53+
getInitialAsyncState: function (params, query, setState) {
54+
return {
55+
user: fetchUser(params.userId),
56+
activity: fetchActivityForUser(params.userId)
57+
}
58+
}
59+
},
60+
61+
render: function() {
62+
return this.state.user ?
63+
<LoadingUserProfile/> :
64+
<UserProfile user={this.state.user} activity={this.state.activity} />;
65+
}
66+
});
67+
```
68+
69+
But you can get fancier...
70+
4571

4672
```js
4773
var User = React.createClass({

0 commit comments

Comments
 (0)