Skip to content

Commit 531ad92

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 <[email protected]>
1 parent 0c0ea75 commit 531ad92

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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)