Download chakra-ui/packages/react/src/components/client-only/client-only.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 765 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/components/client-only/client-only.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/components/client-only/client-only.tsx
-
curl -L -o client-only.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/components/client-only/client-only.tsx
765 Bytes
| "use client" | |
| import { useEffect, useState } from "react" | |
| import { Show } from "../show" | |
| export interface ClientOnlyProps { | |
| /** | |
| * The content to render on the client side. | |
| * | |
| * **Note:** Use the function pattern when accessing browser-only APIs. | |
| */ | |
| children: React.ReactNode | (() => React.ReactNode) | |
| /** | |
| * The fallback content to render while the component is mounting on the client | |
| * side. | |
| */ | |
| fallback?: React.ReactNode | undefined | |
| } | |
| export const ClientOnly = (props: ClientOnlyProps) => { | |
| const { children, fallback } = props | |
| const [hasMounted, setHasMounted] = useState(false) | |
| useEffect(() => { | |
| setHasMounted(true) | |
| }, []) | |
| return ( | |
| <Show when={hasMounted} fallback={fallback}> | |
| {children} | |
| </Show> | |
| ) | |
| } | |