Skip to content

Commit 2d93373

Browse files
add one more example to README
1 parent 1fb0c44 commit 2d93373

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ async function* PokemonInfoPage({ pokemonId, pokemonName }) {
4242
export default Coroutine.create(PokemonInfoPage);
4343
```
4444

45+
```javascript
46+
class MyComponent extends Coroutine {
47+
async observe() {
48+
try {
49+
const users = await Users.retrieve();
50+
return { status: 'success', users };
51+
} catch (error) {
52+
return { status: 'failure', error };
53+
}
54+
}
55+
56+
render() {
57+
switch (this.state.data.status) {
58+
case 'success':
59+
return <UserList users={this.state.data.users} />;
60+
case 'failure':
61+
return <ErrorMessage error={this.state.data.error} />;
62+
default:
63+
return <Loading />;
64+
}
65+
}
66+
}
67+
```
68+
4569
## Usage
4670

4771
See [details page](https://react-coroutine.js.org/Details.html) for more.

0 commit comments

Comments
 (0)