import Demo from "./src/components/Demo" import Layout from "./src/components/Layout"
export default Layout
After @acdlite merged facebook/react#13398, I was curiuos if it would be possible to render an async component like:
async function Repos({ user }) {
const res = await fetch(...)
const repos = await res.json()
return <ul>{repos.map(...)}</ul>
}
Available at https://react-lazy-example-qmehmnudqu.now.sh/
-
Clone this repo.
-
Next, we need a custom build of React with Suspense enabled:
git submodule update
to install https://github.com/facebook/react/.yarn patch
to setenableSuspense = true
yarn build
to build React with Suspense.
-
yarn install
-
yarn dev