Back to Snowpack

React + Loadable Components

examples/react-loadable-components/README.md

3.8.5683 B
Original Source

Based on app-template-react

You can lazy load React components in Snowpack when needed with React‘s builtin React.lazy (docs):

jsx
import React, {useState, useEffect, Suspense} from 'react';

const Async = React.lazy(() => import('./Async'));

function Component() {
  return (
    <div>
      <Suspense fallback={<div>Loading...</div>}>
        <Async />
      </Suspense>
    </div>
  );
}

This works out-of-the-box in Snowpack, with no configuration needed!

Learn more