BridgeBeta
  • Brand
  • Digital Assets
    Foundations
    Icons
    Components
    Templates
  • Resources
    Design Tokens
    How-tos
    Best Practices
    Libraries
    Accessibility
    Products List
  • Support
    • Overview
    • Actions
      • Overview
      • Button
      • ContextMenu
      • Link
    • Controls
      • Overview
      • Checkbox
      • Tag
      • Toggle
    • Forms
      • Overview
      • DatePicker
      • FileUploader
      • Input
      • NumberInput
      • RadioButton
      • Search
      • Select
      • Slider
      • TextArea
      • TextInput
    • Hooks
      • useIsomorphicLayoutEffect
      • useMediaQuery
      • useSettings
    • Navigation
      • Overview
      • AnchorNavigation
      • BannerNavigation
      • Breadcrumb
      • Footer
      • InfoBar
      • MainNavigation
      • SecondaryNavigation
      • StepNavigation
      • SubNavigation
    • Overlay
      • Overview
      • Credits
      • Modal
      • ModalWrapper
      • Notification
      • Tooltip
    • Structure
      • Overview
      • Accordion
      • AuthLayout
      • Avatar
      • Callout
      • Card
      • ContentSwitcher
      • Empty
      • Hero
      • InlineLoading
      • Item
      • List
      • Loading
      • mdxComponents
      • Module
      • Pagination
      • ReadMore
      • Story
      • Table
      • Tabs
      • Text
      • Unit
      • User
      • WFPCoreProvider
      • Wrapper
Components
Navigation
MainNavigation

useMainNavigation

  • Design
  • Code
  • Props
  • useMainNavigation

The useMainNavigation hook can be used inside the MainNavigation to access and control the state of the Navigation. It allows you to access the context of the MainNavigation which stores the state of the MainNavigation.

Usage

import { useMainNavigation } from "@wfp/react";
function ComponentInsideMainNavigation() {
const { onChangeSub, activeMenuItem, openMobileMenu, toggleMenu } =
useMainNavigation();
return <Button onClick={() => toggleMenu()}>Toggle Menu</Button>;
}

Return value definitions

export interface MainNavigationContextType {
/**
* Callback when the user clicks on a sub menu item
*/
onChangeSub: (action: string, i?: string, event?: any) => void;
/**
* The active menu item
*/
activeMenuItem?: string | null;
/**
* Whether the mobile menu is open
*/
openMobileMenu: boolean;
/**
* Toggle the mobile menu
*/
toggleMenu: () => void;
}

onChangeSub

The action can be toggle or close. i is the ID (number) of the SubMenuItem that should be triggered. Optionally add the native event to prevent its default behaviour.

toggleFirstSubMenuItem = () => {
onChangeSub("toggle", 0);
};
closeMenu = () => {
onChangeSub("close");
};

activeMenuItem

Returns the index of the currently active SubMenuItem. Returns null if no SubMenu is opened.

const { activeMenuItem } = useMainNavigation();

toggleMenu

TODO: Rename the function name to toggleMobileMenu, also add true/false optional.

The toggleMenu function allows you to toggle mobile navigation

const toggleMenu = () => {
setOpenMobileMenu(!openMobileMenu);
};

openMobileMenu

Opens or closes the mobile navigation.

setOpenMobileMenu(true);

On this page

  • Usage
  • Return value definitions
  • onChangeSub
  • activeMenuItem
  • toggleMenu
  • openMobileMenu

References

  • Storybook
Storybook
Figma library
Contact us
2025 © World Food Programme