Socket
Book a DemoInstallSign in
Socket

usecontextmenu-react

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usecontextmenu-react

Contextmenu hook in React

1.0.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

usecontextmenu-react

Contextmenu hook in React

NPM Package

Install

Using npm

npm install --save usecontextmenu-react

Usage

import {ContextMenu, ContextMenuItem, useContextMenu} from 'usecontextmenu-react';

Example

See example folder

import React, {useRef} from "react";
import {ContextMenu, ContextMenuItem, useContextMenu} from 'usecontextmenu-react';

const Example = () => {
    const {menuProps, onContextMenu, visibleOnPosition} = useContextMenu();

    const blockStyle = {
        height: '200px',
        backgroundColor: 'tomato',
    }
    
    return (
        <div>
            <div onContextMenu={onContextMenu} style={blockStyle}/>

            <ContextMenu {...menuProps}>
                <ContextMenuItem>Lorem ipsum dolor</ContextMenuItem>
                <ContextMenuItem disabled>Disabled</ContextMenuItem>
                <ContextMenuItem onClick={() => console.log('Click!')}>onClick</ContextMenuItem>
                <ContextMenuItem>Lorem ipsum dolor sit</ContextMenuItem>
            </ContextMenu>
        </div>
    );
}

API

useContextMenu({onShow, onHide})

onShow: () => void - Called when the menu is visible

onHide: () => void - Called when the menu is hidden

This hook returns an object containing the following properties:

onContextMenu - The event that triggered the context menu

menuProps - Context menu props

visibleOnPosition({x: number, y: number}) - Display the context menu on custom position. You can provide x and y coordinates

License

MIT © n0mver

Keywords

contextmenu

FAQs

Package last updated on 29 Oct 2021

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.