Skip to content

Commit 7193449

Browse files
committed
Prevent crash when settings control is enabled in ControlBar
Replace `useLayoutContext()` with `useMaybeLayoutContext()` in `useSettingsToggle` to handle cases where `LayoutContext` is not provided, preventing crashes when settings control is enabled in `ControlBar` component. Signed-off-by: Sora Morimoto <sora@morimoto.io>
1 parent 0c0ea75 commit 7193449

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/sweet-parks-shake.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@livekit/components-react': patch
3+
---
4+
5+
Prevent crash when `settings` control is enabled in `ControlBar`.
6+
7+
Replace `useLayoutContext()` with `useMaybeLayoutContext()` in
8+
`useSettingsToggle` to handle cases where `LayoutContext` is not provided,
9+
preventing crashes when settings control is enabled in `ControlBar` component.

packages/react/src/hooks/useSettingsToggle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLayoutContext } from '../context';
1+
import { useMaybeLayoutContext } from '../context';
22
import { mergeProps } from '../mergeProps';
33
import * as React from 'react';
44

@@ -15,7 +15,8 @@ export interface UseSettingsToggleProps {
1515
* @alpha
1616
*/
1717
export function useSettingsToggle({ props }: UseSettingsToggleProps) {
18-
const { dispatch, state } = useLayoutContext().widget;
18+
const layoutContext = useMaybeLayoutContext();
19+
const { dispatch, state } = layoutContext?.widget ?? {};
1920
const className = 'lk-button lk-settings-toggle';
2021

2122
const mergedProps = React.useMemo(() => {

0 commit comments

Comments
 (0)