Spaces:
Runtime error
Runtime error
Download streaming-react-app/src/useStable.ts from MACXXX/seamless-streaming: direct link, hf CLI and curl.
- Browser
- Download file 498 Bytes
-
https://huggingface.co/spaces/MACXXX/seamless-streaming/resolve/main/streaming-react-app/src/useStable.ts
- Command line
-
hf download hf://spaces/MACXXX/seamless-streaming/streaming-react-app/src/useStable.ts
-
curl -L -o useStable.ts https://huggingface.co/spaces/MACXXX/seamless-streaming/resolve/main/streaming-react-app/src/useStable.ts
498 Bytes
| import {useRef} from 'react'; | |
| type UninitializedMarker = Readonly<Record<string, unknown>> | symbol; | |
| const UNINITIALIZED: UninitializedMarker = | |
| typeof Symbol === 'function' && typeof Symbol() === 'symbol' | |
| ? Symbol() | |
| : Object.freeze({}); | |
| export default function useStable<T>(initialValueCallback: () => T): T { | |
| const ref = useRef<T | UninitializedMarker>(UNINITIALIZED); | |
| if (ref.current === UNINITIALIZED) { | |
| ref.current = initialValueCallback(); | |
| } | |
| return ref.current as T; | |
| } | |