diff --git a/src/index.ts b/src/index.ts
index eb1c78d5e..7aa1fca5c 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -21,6 +21,7 @@ export {
formatRelativeDate,
formatDateTime,
} from './util/date-and-time';
+export { lazy } from './util/lazy';
export { ListenerCollection } from './util/listener-collection';
export { confirm } from './util/prompts';
diff --git a/src/pattern-library/components/PlaygroundApp.tsx b/src/pattern-library/components/PlaygroundApp.tsx
index d7a5a5510..a1e3b96e0 100644
--- a/src/pattern-library/components/PlaygroundApp.tsx
+++ b/src/pattern-library/components/PlaygroundApp.tsx
@@ -147,6 +147,7 @@ export default function PlaygroundApp({
const prototypeRoutes = getRoutes('prototype');
const hookRoutes = getRoutes('hooks');
+ const utilityRoutes = getRoutes('utilities');
const groupKeys = Object.keys(componentGroups) as Array<
keyof typeof componentGroups
@@ -204,6 +205,13 @@ export default function PlaygroundApp({
))}
+ Utilities
+
+ {utilityRoutes.map(route => (
+
+ ))}
+
+
{prototypeRoutes.length > 0 && (
<>
Prototypes
diff --git a/src/pattern-library/components/patterns/utilities/LazyPage.tsx b/src/pattern-library/components/patterns/utilities/LazyPage.tsx
new file mode 100644
index 000000000..206414696
--- /dev/null
+++ b/src/pattern-library/components/patterns/utilities/LazyPage.tsx
@@ -0,0 +1,114 @@
+import Library from '../../Library';
+
+export default function LazyPage() {
+ return (
+
+ The lazy utility creates a component which is loaded
+ asynchronously, displaying fallback content while loading and showing
+ an error fallback if the component fails to load.
+
+ }
+ >
+
+
+
+
+
+
+
+
+ Display name for the lazy wrapper component.
+
+
+ string
+
+
+
+
+
+
+
+ Callback invoked on first render to load the component. This
+ returns a promise resolving to the loaded component. A common
+ use case is to use an import(...) expression to
+ load the component.
+
+
+ {'() => Promise>'}
+
+
+
+
+
+
+
+ Configuration for the lazy component
+
+
+ LazyOptions<P>
+
+
+
+
+
+
+
+
+
+ Function that returns content to display while loading
+
+
+ {'(props: P) => ComponentChildren'}
+
+
+
+
+
+
+
+ Function that returns content to display if loading fails. If
+ not provided a default error fallback is shown.
+
+
+
+ {
+ '((props: P, error: Error) => ComponentChildren) | undefined'
+ }
+
+
+
+ undefined
+
+
+
+
+
+
+
+
+
+ Lazy components start loading on first render, and show a fallback
+ while loading.
+
+
+
+
+
+
If a component fails to load, the error fallback is displayed:
= {
+ /** Returns the content to render if the component is not yet loaded. */
+ fallback: (props: P) => ComponentChildren;
+ /** Returns the content to render if the component failed to load. */
+ errorFallback?: (props: P, err: Error) => ComponentChildren;
+};
+
+/**
+ * Create a lazy-loading version of a component.
+ *
+ * This utility allows deferring loading the code for a component until it is
+ * rendered. The returned component loads in two phases. In the first phase a
+ * placeholder is rendered and the {@link load} callback is invoked to load
+ * the component. Then when the returned promise resolves, the placeholder is
+ * replaced with the real compoonent.
+ *
+ * @param displayName - Display name for the lazy wrapper component
+ * @param load - A function which loads the JS component. This will usually
+ * be an async function which does `import('path/to/module')` and then returns
+ * one of the loaded module's exports.
+ * @param options - Options that specify what to render while the component is
+ * loading or if it fails to load.
+ */
+export function lazy