useOptionalMenuContext
Hook to access a Menu context when one is available
Import
import { useOptionalMenuContext } from "@videojs/react";Usage
Use the optional hook when a component can work both inside and outside Menu.Root.
function MenuAwareLabel() {
const menu = useOptionalMenuContext();
return <span>{menu ? "Nested in a menu" : "Standalone"}</span>;
}It returns null instead of throwing when no menu context is available.
API Reference
Return Value
| Property | Type | Details |
|---|---|---|
core | MenuCore | |
menu | object | |
| ||
parent | object | |
| ||
state | MenuState | |
preferredSide | MenuState['side'] | |
setPositionedSide | function | |
| ||
contentId | string | |
anchorName | string | |
boundary | 'viewport' | 'container' | string & o... | |
| ||
container | object | null | |