Skip to content

Instantly share code, notes, and snippets.

@samMeow
Last active August 16, 2019 06:45
Show Gist options
  • Save samMeow/0abbc70b7cc2284653838b35f497afa2 to your computer and use it in GitHub Desktop.
Save samMeow/0abbc70b7cc2284653838b35f497afa2 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
let shouldRender = false;
const Children = () => {
if (shouldRender) {
return (<div>Hello world</div>);
}
throw new Promise((resolve) => {
setTimeout(() => {
shouldRender = true;
resolve();
}, 2000);
});
}
const App = ({ children }) => (
<div>
<h1>Wait for something</h1>
<React.Suspense fallback={<span>Loading</span>}>
{children}
</React.Suspense>
</div>
);
ReactDOM.render(<App/>, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment