Skip to content

Instantly share code, notes, and snippets.

@dance2die dance2die/index.js
Created Aug 1, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.