Skip to content

Instantly share code, notes, and snippets.

@ngbrown
Created December 27, 2023 18:58
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 ngbrown/04108e20f2ddf6af980a2ae51332f48d to your computer and use it in GitHub Desktop.
Save ngbrown/04108e20f2ddf6af980a2ae51332f48d to your computer and use it in GitHub Desktop.
Remix Client Only Component
import React, { ComponentType, lazy, Suspense } from "react";
export function ClientOnly({
fallback,
component,
}: {
fallback: React.ReactElement;
component: Promise<{ default: ComponentType<any> }>;
}) {
const LazyComponent = lazy(() => component);
return (
<Suspense fallback={fallback}>
<LazyComponent />
</Suspense>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment