Skip to content

Commit 7333c8f

Browse files
committed
fix(cmd-k): Move ref write into useEffect to fix rules of hooks
stateRef.current = state during render violates rules of hooks. Move it into a useEffect so the write happens after render.
1 parent 4d22b1c commit 7333c8f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

static/app/components/commandPalette/useCommandPaletteAnalytics.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export function useCommandPaletteAnalytics(filteredActionCount: number): {
4444
const sessionIdRef = useRef(uniqueId('cmd-palette-'));
4545

4646
const stateRef = useRef(state);
47-
stateRef.current = state;
47+
useEffect(() => {
48+
stateRef.current = state;
49+
});
4850

4951
const openedAtRef = useRef(Date.now());
5052
const actionsSelectedRef = useRef(0);

0 commit comments

Comments
 (0)