11import React , { useCallback , useEffect , useState } from 'react' ;
22import { ContextMenuWrapper } from 'react-context-menu-wrapper' ;
33
4- const MyContextMenu = ( ) => {
4+ const MyContextMenu = React . memo ( ( ) => {
55 const [ seconds , setSeconds ] = useState ( 0 ) ;
66 useEffect ( ( ) => {
7- const timer = setInterval ( ( ) => setSeconds ( s => s + 1 ) , 1000 ) ;
7+ const timer = setInterval ( ( ) => setSeconds ( s => s + 0.5 ) , 500 ) ;
88 return ( ) => clearInterval ( timer ) ;
9- } ) ;
9+ } , [ ] ) ;
1010
1111 return (
1212 < div className = "context-menu" >
1313 < p >
14- I am a custom < strong > global</ strong > context menu!
15- </ p >
16- < p >
17- Open for { seconds } { seconds === 1 ? 'second' : 'seconds' } .
14+ This is a < strong > global</ strong > menu.
15+ < div style = { { height : 10 } } />
16+ Open for { seconds . toFixed ( 1 ) } { seconds === 1 ? 'second' : 'seconds' } .
1817 </ p >
18+ < button > Dummy button #1</ button >
19+ < button > Dummy button #2</ button >
1920 </ div >
2021 ) ;
21- } ;
22+ } ) ;
2223
23- const GlobalMenuExample = ( ) => {
24+ const GlobalMenuExamplePage = React . memo ( ( ) => {
2425 const [ globalMenuEnabled , setGlobalMenuEnabled ] = useState ( true ) ;
2526 const onClick = useCallback ( ( ) => setGlobalMenuEnabled ( ! globalMenuEnabled ) , [ globalMenuEnabled ] ) ;
2627
27- const status = globalMenuEnabled ? 'ENABLED' : 'DISABLED' ;
28+ const currentMenuType = globalMenuEnabled ? 'custom' : "Browser's default" ;
29+ const currentMenuTypeStyle = { color : globalMenuEnabled ? 'red' : 'green' } ;
2830 const action = globalMenuEnabled ? 'Disable' : 'Enable' ;
2931
3032 return (
3133 < React . Fragment >
32- < p className = "text" > Custom global context menu status: { status } </ p >
34+ < p className = "text" >
35+ Currently using < span style = { currentMenuTypeStyle } > { currentMenuType } </ span > global context menu.
36+ </ p >
3337 < button className = "button" onClick = { onClick } >
3438 { action } custom global context menu
3539 </ button >
@@ -41,6 +45,6 @@ const GlobalMenuExample = () => {
4145 ) }
4246 </ React . Fragment >
4347 ) ;
44- } ;
48+ } ) ;
4549
46- export default GlobalMenuExample ;
50+ export default GlobalMenuExamplePage ;
0 commit comments