| 1 | let promise = null; |
| 2 | let isResolved = false; |
| 3 | |
| 4 | export default function Suspend({children}) { |
| 5 | // This will suspend the content from rendering but only on the client. |
| 6 | // This is used to demo a slow loading app. |
| 7 | if (!isResolved) { |
| 8 | if (promise === null) { |
| 9 | promise = new Promise(resolve => { |
| 10 | setTimeout( |
| 11 | () => { |
| 12 | isResolved = true; |
| 13 | resolve(); |
| 14 | }, |
| 15 | typeof window === 'object' ? 6000 : 1000 |
| 16 | ); |
| 17 | }); |
| 18 | } |
| 19 | throw promise; |
| 20 | } |
| 21 | return children; |
| 22 | } |