Skip to content

Commit

Permalink
Lazily load the game react components
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyJames committed Jul 17, 2021
1 parent f6ffbd8 commit e86dc93
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
12 changes: 10 additions & 2 deletions app/src/games/chess/client/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import Host from "./Host";
import Guest from "./Guest";
import { Suspense, lazy } from "react";

const withSuspense = (Component) => (props) => (
<Suspense fallback="Loading...">
<Component {...props}/>
</Suspense>
)

const Host = withSuspense(lazy(() => import("./Host")))
const Guest = withSuspense(lazy(() => import("./Guest")))

export { Host, Guest }
12 changes: 10 additions & 2 deletions app/src/games/hot-potato/client/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import Host from "./Host";
import Guest from "./Guest";
import { Suspense, lazy } from "react";

const withSuspense = (Component) => (props) => (
<Suspense fallback="Loading...">
<Component {...props}/>
</Suspense>
)

const Host = withSuspense(lazy(() => import("./Host")))
const Guest = withSuspense(lazy(() => import("./Guest")))

export { Host, Guest }
15 changes: 12 additions & 3 deletions app/src/games/tic-tac-toe/client/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import Guest from "./Guest";
import Host from "./Host";
export { Guest, Host };
import { Suspense, lazy } from "react";

const withSuspense = (Component) => (props) => (
<Suspense fallback="Loading...">
<Component {...props}/>
</Suspense>
)

const Host = withSuspense(lazy(() => import("./Host")))
const Guest = withSuspense(lazy(() => import("./Guest")))

export { Host, Guest }
12 changes: 10 additions & 2 deletions app/src/games/whist/client/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import Host from "./Host";
import Guest from "./Guest";
import { Suspense, lazy } from "react";

const withSuspense = (Component) => (props) => (
<Suspense fallback="Loading...">
<Component {...props}/>
</Suspense>
)

const Host = withSuspense(lazy(() => import("./Host")))
const Guest = withSuspense(lazy(() => import("./Guest")))

export { Host, Guest }

0 comments on commit e86dc93

Please sign in to comment.