swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.25k stars 744 forks source link

How to use this in React + webpack env #680

Closed rkaliyug closed 5 years ago

rkaliyug commented 5 years ago

Hi,

I am trying to use in ReactJs+webpack environemnt, I have used it as below

Added below command in package.json to install npm package
jquery.contextmenu": "next",

import $ from "jquery"; import contextMenu from "jquery-contextmenu";

class ContextMenuHandler {

constructor() {

$.contextMenu({
  // define which elements trigger this menu
  selector: ".node",
  // define the elements of the menu
  items: {
    foo: { name: "Foo", callback: function (key, opt) { alert("Foo!"); } },
    bar: { name: "Bar", callback: function (key, opt) { alert("Bar!"); } }
  }
  // there's more, have a look at the demos and docs...
});

}

}

I am getting below error. Do you have suggestions? ReferenceError: $ is not defined

rkaliyug commented 5 years ago

I resolved it by wrapping the code inside document ready event

bbrala commented 5 years ago

Glad it worked out