Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.

Add partially rendering example #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
flex-direction: row;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
Expand Down
15 changes: 13 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component, Suspense, lazy, memo } from "react";
import React, { Component, Suspense, lazy, memo, Fragment } from "react";
import "./App.css";

const sleep = ms => new Promise(r => setTimeout(r, ms));
Expand All @@ -8,6 +8,11 @@ const Logo = lazy(async () => {
return import("./logo.js");
});

const LargeLogo = lazy(async () => {
await sleep(3000);
return import("./logo.js");
});

const Placeholder = memo(() => <strong>Loading...</strong>);

class App extends Component {
Expand All @@ -21,9 +26,15 @@ class App extends Component {
render() {
return (
<div className="App">
<input type="text" />
<header className="App-header">
<Suspense maxDuration={300} fallback={<Placeholder />}>
<Logo alt={this.state.alt} />
<Fragment>
<Logo alt={this.state.alt} />
<Suspense maxDuration={1500} fallback={<Placeholder />}>
<LargeLogo alt={this.state.alt} />
</Suspense>
</Fragment>
</Suspense>
</header>
</div>
Expand Down