Download mobile/modules/engine/src/react/useEngineSnapshot.ts from Anirudh1950/MentraOS: direct link, hf CLI and curl.
- Browser
- Download file 574 Bytes
-
https://huggingface.co/Anirudh1950/MentraOS/resolve/main/mobile/modules/engine/src/react/useEngineSnapshot.ts
- Command line
-
hf download hf://Anirudh1950/MentraOS/mobile/modules/engine/src/react/useEngineSnapshot.ts
-
curl -L -o useEngineSnapshot.ts https://huggingface.co/Anirudh1950/MentraOS/resolve/main/mobile/modules/engine/src/react/useEngineSnapshot.ts
574 Bytes
| import {useEffect, useRef, useState} from "react" | |
| export function useEngineSnapshot<T>(getSnapshot: () => T, subscribe: (onChange: () => void) => () => void): T { | |
| const getSnapshotRef = useRef(getSnapshot) | |
| const subscribeRef = useRef(subscribe) | |
| getSnapshotRef.current = getSnapshot | |
| subscribeRef.current = subscribe | |
| const [snapshot, setSnapshot] = useState(() => getSnapshot()) | |
| useEffect(() => { | |
| setSnapshot(getSnapshotRef.current()) | |
| return subscribeRef.current(() => setSnapshot(getSnapshotRef.current())) | |
| }, []) | |
| return snapshot | |
| } | |