Last active
April 5, 2020 09:24
-
-
Save pereslavtsev/ddc1da394cb952bfec26caf471dfa8fc to your computer and use it in GitHub Desktop.
Custom React hook `useContextMenu` provides to create a menu context menus in Electron-based apps. Inspired by `react-electron-contextmenu` - https://github.com/johot/react-electron-contextmenu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import useContextMenu from './useContextMenu'; | |
const App = () => { | |
const items = React.useMemo( | |
() => [ | |
{ | |
label: 'Item 1', | |
click: () => { | |
console.log('clicked item 1'); | |
}, | |
}, | |
{ | |
type: 'separator', | |
}, | |
{ | |
label: 'Item 2', | |
click: () => { | |
console.log('clicked item 2'); | |
}, | |
}, | |
], | |
[], | |
); | |
const [ref] = useContextMenu(items); | |
return ( | |
<div> | |
<div ref={ref}> | |
context menu area | |
</div> | |
<button>Simple button</button> | |
</div> | |
); | |
} | |
export defaul App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment