Created
December 27, 2023 18:58
-
-
Save ngbrown/04108e20f2ddf6af980a2ae51332f48d to your computer and use it in GitHub Desktop.
Remix Client Only Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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