Download chakra-ui/packages/react/src/hooks/use-const.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 306 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/hooks/use-const.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/hooks/use-const.ts
-
curl -L -o use-const.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/hooks/use-const.ts
306 Bytes
| "use client" | |
| import { useRef } from "react" | |
| type InitFn<T> = () => T | |
| export function useConst<T extends any>(init: T | InitFn<T>): T { | |
| const ref = useRef(null) | |
| if (ref.current === null) { | |
| // @ts-ignore | |
| ref.current = typeof init === "function" ? init() : init | |
| } | |
| return ref.current as T | |
| } | |