# use-electron-context-menu

> Electron context menu React hook

Latest version **1.0.2** (published 2021-02-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install use-electron-context-menu
pnpm add use-electron-context-menu
yarn add use-electron-context-menu
bun add use-electron-context-menu
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-02-11 |
| First published | 2021-02-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Matthias Halfmann |
| Maintainers | matthiaaas |
| Keywords | react, hook, electron, context, menu, native, typescript |

## Links

- npm: https://www.npmjs.com/package/use-electron-context-menu
- Repository: https://github.com/transflow/use-electron-context-menu
- Homepage: https://github.com/transflow/use-electron-context-menu#readme
- Issues: https://github.com/transflow/use-electron-context-menu/issues
- npm.io page: https://npm.io/package/use-electron-context-menu

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-02-11
- 1.0.1 — 2021-02-10
- 1.0.0 — 2021-02-10

## README

# use-electron-context-menu

`0` dependencies

## Installation

```bash
npm install use-electron-context-menu
```

_Note_: If you prefer `yarn` instead of `npm`, just use `yarn add use-electron-context-menu`.

## How to use

```tsx
import React, { useRef } from "react"
import useContextMenu from "use-electron-context-menu"

export default function App() {
  const ref = useRef(null)

  useContextMenu(ref, [
    {
      label: "Copy",
      click: () => console.log("copied")
    }
  ])

  return (
    <div ref={ref} style={{ width: 200, height: 100 }}>
      {/* right clicking this area will spawn the context menu */}
    </div>
  )
}
```

## API

```ts
const { closeMenu } = useContextMenu(ref, menuItems, options)
```

### Parameters

- `ref`: React element you want to add the context menu to
- `menuItems`: An array of Electron [menu items](https://www.electronjs.org/docs/api/menu-item)
- `options`: _(optional)_ An object of options for this hook

### Return Values

- `closeMenu()`: Force the context menu to close

### Options

- `x`: Display context menu at fixed x coordinate
- `y`: Display context menu at fixed y coordinate
- `onContext(event)`: Called when context menu opens
- `onClose()`: Called when context menu closes

---
_Source: https://npm.io/package/use-electron-context-menu · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
