npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-json-context-menu

v1.0.3

Published

A React Typescript class component to facilitate the integration of newer versions of react-contexify (>=6.0.0) with my own UI applications

Readme

react-json-context-menu

A React Typescript class component to facilitate the integration of newer versions of react-contexify with my existing applications

Use case

The react-contexify library is an excellent library designed for displaying context menus. However, it can be inconvenient to create a menu from React component every I need a new Context Menu. For my purposes, it is far more convenient to define a menu using a JSON object, allowing me to easily call and display the context menu from anywhere.

Menus are defined as an array of items, for instance:

    [
        { label: 'Option 1', title: 'Option 1', action: () => console.log('Option 1 selected'), disabled: true },
        { separator: true },
        { label: 'Option 2', title: 'Option 2', action: () => console.log('Option 2 selected') }
    ]

How to install:

npm install react-json-context-menu react-contexify

How to include

Import code

import {JSONContextMenuProvider} from "react-json-context-menu";

Import the styles directly from react-contexify library:

import 'react-contexify/ReactContexify.css';

To use

Add the JSONContextMenuProvider wrapping your app

createRoot(document.getElementById('root')!).render(
  <StrictMode>
      <JSONContextMenuProvider>
            <App />
      </JSONContextMenuProvider>
  </StrictMode>
)

Create your menu by simply adding the component at the end of your App

Create a context-menu in your App:

    <JSONContextMenu theme="dark" />

Use the hook to open a context menu from any component

// Import type and hook
import {type ContextMenuItems, useJSONContextMenu} from "react-json-context-menu";

// Use Hook to gain access to `showContextMenu`

const {showContextMenu} = useJSONContextMenu();

const handleContextMenu = (event:  React.MouseEventHandler<HTMLElement>) => {
    // Define your menu as a JSON object
    const menuItems: ContextMenuItems = [
        { label: 'Option 1', title: 'Option 1', action: () => console.log('Option 1 selected'), disabled: true },
        { separator: true },
        { label: 'Option 2', title: 'Option 2', action: () => console.log('Option 2 selected') }
    ];
    // Open your menu on response to an event
    showContextMenu({event, items: menuItems})
};

Now wire your React components, to mouse events onClick or onContextMenu

<div>
    <button onClick={(event) => handleContextMenu(event)}>
        Context Menu
    </button>
    <button onContextMenu={handleContextMenu}>
        Context Menu Right Click
    </button>
</div>

Open ContextMenu without event

If you want to trigger opening the Context Menu but you don't have an event you can, but you need to provide the position to display the Context Menu as position

const openMenuWithOutEvent = (x: number, y: number) => {
    // Define your menu as a JSON object
    const menuItems: ContextMenuItems = [
        { label: 'Option 1', title: 'Option 1', action: () => console.log('Option 1 selected'), disabled: true },
        { separator: true },
        { label: 'Option 2', title: 'Option 2', action: () => console.log('Option 2 selected') }
    ];
    // Open your menu on response to an event
    showContextMenu({position: {x, y}, items: menuItems})
};

Small sample here: https://codesandbox.io/p/sandbox/test-react-json-context-menu-hvq7nx