Skip to content

Instantly share code, notes, and snippets.

View e-dong's full-sized avatar

Eric Dong e-dong

  • General Dynamics
  • Pittsburgh,PA
View GitHub Profile
@e-dong
e-dong / useHandleMenuOpenState.ts
Last active August 1, 2021 13:45
React hook to manage open state of context menu
/**
* Handle the open/close state of a context menu and the element that triggers it.
* The following cases are taken cared of:
* - Clicking the trigger element will toggle the menu open or close
* - If the menu is open, clicking outside the menu will close it
* - If the menu is open, pressing the esc key will close it
* - The menu may be opened/closed externally since this hook returns the setState function
*
* Example Usage:
* import { useHandleMenuOpenState } from 'utils/userInputHandlers';