Socket
Socket
Sign inDemoInstall

use-electron-context-menu

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-electron-context-menu

Electron context menu React hook


Version published
Maintainers
1
Install size
5.97 kB
Created

Readme

Source

use-electron-context-menu

0 dependencies

Installation

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

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

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
  • 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

Keywords

FAQs

Last updated on 11 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc