nit
This commit is contained in:
@@ -106,9 +106,11 @@ export function useStreamPlayback(
|
||||
const [state, dispatch] = useReducer(playbackReducer, initialState);
|
||||
// Track the stream ID we've initialized for, to reset when navigating between streams
|
||||
const initializedForRef = useRef<string | null>(null);
|
||||
// Latest currentIndex for onParticleRemoved (passed to the subscription), so
|
||||
// it reads the current value without re-subscribing. useEffectEvent can't be
|
||||
// used — it may not be passed to another hook.
|
||||
// Latest currentIndex for onParticleRemoved, which is passed into
|
||||
// useLiveParticleChildren. Reading it through a ref keeps the callback stable
|
||||
// (no re-subscription) and breaks the declaration cycle
|
||||
// children -> currentIndex -> callback -> children. useEffectEvent can't be
|
||||
// used here — Effect Events may not be passed to another hook.
|
||||
const currentIndexRef = useRef(0);
|
||||
|
||||
// --- Firestore change callbacks ---
|
||||
@@ -147,7 +149,7 @@ export function useStreamPlayback(
|
||||
|
||||
const currentParticle = currentIndex !== -1 ? children[currentIndex] : null;
|
||||
|
||||
// Keep the latest-index ref in sync for onParticleRemoved (above).
|
||||
// Keep the ref read by onParticleRemoved in sync with the derived index.
|
||||
useEffect(() => {
|
||||
currentIndexRef.current = currentIndex;
|
||||
}, [currentIndex]);
|
||||
|
||||
Reference in New Issue
Block a user