Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created August 1, 2019 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/57aef9fb69e78008c8e693b9487a0998 to your computer and use it in GitHub Desktop.
Save dance2die/57aef9fb69e78008c8e693b9487a0998 to your computer and use it in GitHub Desktop.
Gatsby using Suspense that fails to build
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