Skip to content

Commit

Permalink
Don't break the rules of hooks 🪝
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Dec 12, 2024
1 parent d00737c commit 58a8868
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/components/src/menu/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ export const MenuPopover = forwardRef<
) {
const menuContext = useContext( MenuContext );

if ( ! menuContext?.store ) {
throw new Error(
'Menu.Popover can only be rendered inside a Menu component'
);
}

// Extract the side from the applied placement — useful for animations.
// Using `currentPlacement` instead of `placement` to make sure that we
// use the final computed placement (including "flips" etc).
const appliedPlacementSide = Ariakit.useStoreState(
menuContext.store,
menuContext?.store,
'currentPlacement'
).split( '-' )[ 0 ];
)?.split( '-' )[ 0 ];

const hideOnEscape = useCallback(
( event: React.KeyboardEvent< Element > ) => {
Expand All @@ -55,7 +49,7 @@ export const MenuPopover = forwardRef<
[]
);

const computedDirection = Ariakit.useStoreState( menuContext.store, 'rtl' )
const computedDirection = Ariakit.useStoreState( menuContext?.store, 'rtl' )
? 'rtl'
: 'ltr';

Expand All @@ -70,6 +64,12 @@ export const MenuPopover = forwardRef<
[ computedDirection ]
);

if ( ! menuContext?.store ) {
throw new Error(
'Menu.Popover can only be rendered inside a Menu component'
);
}

return (
<Ariakit.Menu
{ ...otherProps }
Expand Down

0 comments on commit 58a8868

Please sign in to comment.