Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/sweet-parks-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@livekit/components-react': patch
---

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.
5 changes: 3 additions & 2 deletions packages/react/src/hooks/useSettingsToggle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutContext } from '../context';
import { useMaybeLayoutContext } from '../context';
import { mergeProps } from '../mergeProps';
import * as React from 'react';

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

const mergedProps = React.useMemo(() => {
Expand Down