Created
August 1, 2019 00:54
-
-
Save dance2die/57aef9fb69e78008c8e693b9487a0998 to your computer and use it in GitHub Desktop.
Gatsby using Suspense that fails to build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Suspense, lazy } from "react" | |
import { graphql, useStaticQuery } from "gatsby" | |
import Layout from "../components/Layout" | |
const importBlock = blockName => | |
lazy(() => import(`../components/blocks/${blockName}/index.js`)) | |
export default () => { | |
const { allDirectory } = useStaticQuery(graphql` | |
{ | |
allDirectory(filter: { relativePath: { ne: "" } }) { | |
edges { | |
node { | |
relativePath | |
id | |
} | |
} | |
} | |
} | |
`) | |
const blocks = allDirectory.edges.map(({ node }) => { | |
const Block = importBlock(node.relativePath) | |
return <Block key={node.id} /> | |
}) | |
return ( | |
<Layout> | |
<Suspense fallback={"loading"}>{blocks}</Suspense> | |
</Layout> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment