Disable Right Click in React.JS Disable Right Click in React.JS reactjs reactjs

Disable Right Click in React.JS


This JS function will prevent bubbling of the contextmenu event, thus preventing the context menu from appearing:

canvas.oncontextmenu = function (e) {    e.preventDefault();};


You could prevent the right-click from actually doing anything by simply ignoring it, like this:

handleMouseDown = e => {  if (e.button === 0)  {    // Actions to perform when left mouse button is clicked, like update state  }}let Canvas = <canvas onMouseDown={this.handleMouseDown} ...>;