Skip to content

Commit

Permalink
Docs: Improve README code example
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Feb 24, 2019
1 parent 7ffca01 commit e5f8649
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,20 @@ In it's `render()` method, the component should throw a Promise which will resol
#### Basic example

```js
let data = null;
let data = null, promise;
function LazyData() {
if (!data) {
const promise = new Promise(
resolve => setTimeout(() => {
if (data) return <div>{data.foo}</div>;

if (!promise) {
promise = new Promise(resolve => {
setTimeout(() => {
data = {foo: 'bar'};
resolve();
}, 1000)
);
throw promise;
}, 1000);
});
}

return <div>{data.foo}</div>;
throw promise;
}

function App() {
Expand Down

0 comments on commit e5f8649

Please sign in to comment.