You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Menu,Item,Separator,Submenu,useContextMenu}from'react-contexify';import'react-contexify/ReactContexify.css';constMENU_ID='blahblah';functionApp(){const{ show }=useContextMenu({id: MENU_ID,});functionhandleContextMenu(event){show({
event,props: {key: 'value'}})}// I'm using a single event handler for all items// but you don't have too :)consthandleItemClick=({ id, event, props })=>{switch(id){case"copy":
console.log(event,props)break;case"cut";console.log(event,props);break;//etc...}}return(<div><ponContextMenu={handleContextMenu}>lorem ipsum blabladhasi blaghs blah</p><Menuid={MENU_ID}><Itemid="copy"onClick={handleItemClick}>Copy</Item><Itemid="cut"onClick={handleItemClick}>Cut</Item><Separator/><Itemdisabled>Disabled</Item><Separator/><Submenulabel="Foobar"><Itemid="reload"onClick={handleItemClick}>Reload</Item><Itemid="something"onClick={handleItemClick}>Do something else</Item></Submenu></Menu></div>);}
Contribute
Any idea and suggestions are welcome. Please have a look at the contributing guide.
License
React Contexify is licensed under MIT.
About
π Add a context menu to your react app with ease