fix: slash command queue race conditions and overlay state management (#246)

This commit is contained in:
Devansh Jain
2025-12-16 15:10:35 -08:00
committed by GitHub
parent 322ab19f11
commit c064d99883
3 changed files with 343 additions and 284 deletions

View File

@@ -0,0 +1,24 @@
import { useCallback, useRef, useState } from "react";
/**
* A custom hook that keeps a React state and ref in sync.
* Useful when you need immediate access to state values in async callbacks
* that may close over stale state. The ref is updated synchronously before
* the state, ensuring reliable checks in async operations.
*
* @param initialValue - The initial state value
* @returns A tuple of [state, setState, ref]
*/
export function useSyncedState(
initialValue: boolean,
): [boolean, (value: boolean) => void, React.MutableRefObject<boolean>] {
const [state, setState] = useState(initialValue);
const ref = useRef(initialValue);
const setSyncedState = useCallback((value: boolean) => {
ref.current = value;
setState(value);
}, []);
return [state, setSyncedState, ref];
}