<ClerkLoading>
The <ClerkLoading>
renders its children while Clerk is loading, and is helpful for showing a custom loading state.
Usage
app/layout.tsximport { ClerkProvider, ClerkLoaded, ClerkLoading } from '@clerk/nextjs' import './globals.css'; export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( <ClerkProvider> <html lang="en"> <body> <ClerkLoading> <div>Clerk is loading...</div> </ClerkLoading> <ClerkLoaded> {children} </ClerkLoaded> </body> </html> </ClerkProvider> ) }
pages/_app.tsximport "@/styles/globals.css"; import { ClerkLoaded, ClerkLoading, ClerkProvider } from "@clerk/nextjs"; import { AppProps } from "next/app"; function MyApp({ Component, pageProps }: AppProps) { return ( <ClerkProvider {...pageProps}> <ClerkLoading> <div>Clerk is loading</div> </ClerkLoading> <ClerkLoaded> <Component {...pageProps} /> </ClerkLoaded> </ClerkProvider> ); } export default MyApp;
app.tsximport { ClerkLoaded, ClerkLoading, ClerkProvider } from '@clerk/clerk-react'; function App() { return ( <ClerkProvider publishableKey={`{{pub_key}}`}> <ClerkLoading> <div>Clerk is loading</div> </ClerkLoading> <ClerkLoaded> <Page /> </ClerkLoaded> <div>This div is always visible</div> </ClerkProvider> ); } function Page() { return <div>The content</div>; } export default App;
routes/index.tsximport { ClerkLoading } from "@clerk/remix"; export default function Index() { return ( <div> <ClerkLoading> <div>Clerk is loading</div> </ClerkLoading> </div> ); }
Last updated on April 11, 2024