import { useState , useCallback , useEffect , useContext } from "react" ; import { FoobarContext } from "@/components/foobar" ; import { handleKonami } from "@/utils/console" ; const KonamiWrapper = ( ) => { const foobarContextObj = useContext ( FoobarContext ) ; const [ konamiCodeInput , setKonamiCodeInput ] = useState < Array < string > > ( [ ] ) ; const handleKonamiCode = useCallback ( ( event ) => { setKonamiCodeInput ( ( prev ) => [ ... prev , event . key ] ) ; } , [ ] ) ; useEffect ( ( ) => { window . addEventListener ( "keydown" , handleKonamiCode ) ; return ( ) => { window . removeEventListener ( "keydown" , handleKonamiCode ) ; } ; } , [ handleKonamiCode ] ) ; useEffect ( ( ) => { if ( foobarContextObj . unlocked ) { const updated = handleKonami ( konamiCodeInput , foobarContextObj ) ; if ( updated ) setKonamiCodeInput ( updated ) ; } } , [ konamiCodeInput ] ) ; return < div />; } ; export { KonamiWrapper } ;