https://github.com/bitmap/use-konami-code
Use the infamous Konami code with a React hook
https://github.com/bitmap/use-konami-code
Last synced: 6 months ago
JSON representation
Use the infamous Konami code with a React hook
- Host: GitHub
- URL: https://github.com/bitmap/use-konami-code
- Owner: bitmap
- Created: 2020-07-26T21:45:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-28T01:27:34.000Z (over 5 years ago)
- Last Synced: 2025-07-14T16:52:34.996Z (7 months ago)
- Language: TypeScript
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# useKonamiCode
⬆️⬆️⬇️⬇️⬅️➡️⬅️➡️🅱️🅰️
Use the infamous Konami code with a React hook.
## Install
```sh
npm install @bitmap/use-konami-code
```
## Usage
For the uninitiated, [The Konami Code](https://en.wikipedia.org/wiki/Konami_Code) is one of the most well known video game cheat codes.
The sequence is `Up`, `Up`, `Down`, `Down`, `Left`, `Right`, `Left`, `Right`, `B`, `A`, `Enter`.
After entering the code, the hook will run whatever callback function you pass to it.
```js
import React, { useState } from 'react'
import { useKonamiCode } from '@bitmap/use-konami-code'
function SecretComponent() {
const [cheatCodeActive, setCheatCodeActive] = useState(false)
useKonamiCode(() => {
setCheatCodeActive(true)
})
if (cheatCodeActive) return (
It’s a secret to everybody.
)
return null
}
```
### Custom cheat code
`useKonamiCode` takes a second argument, which is an array of `keycodeEvent.key` strings. This will allow you to to a custom key sequence.
```js
const godMode = 'iddqd'.split('')
useKonamiCode(callback, godMode)
```