Download react-spring/packages/shared/src/hooks/useConstant.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 296 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/shared/src/hooks/useConstant.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/shared/src/hooks/useConstant.ts
-
curl -L -o useConstant.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/shared/src/hooks/useConstant.ts
296 Bytes
| import { useRef } from 'react' | |
| type Init<T> = () => T | |
| /** | |
| * Creates a constant value over the lifecycle of a component. | |
| */ | |
| export function useConstant<T>(init: Init<T>) { | |
| const ref = useRef<T | null>(null) | |
| if (ref.current === null) { | |
| ref.current = init() | |
| } | |
| return ref.current | |
| } | |