Modal State Hook

Modal State

A powerful hook that provides intelligent modal state management with built-in navigation awareness, accessibility features, and customizable behaviors. Modals automatically close when users navigate back, providing an intuitive user experience.

Navigation-Aware Behavior

The standout feature of createModalState is its intelligent handling of browser navigation. When a modal is open and the user presses the back button, the modal automatically closes instead of navigating away from the page.

How it works:

  1. User opens a modal → History entry is pushed
  2. User presses back button → Modal closes gracefully
  3. URL returns to previous state → No page navigation occurs
  4. User experience feels natural and intuitive
See Example