Socket
Book a DemoInstallSign in
Socket

use-konami-code

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-konami-code

useKonamiCode React Hook.

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
8
166.67%
Maintainers
1
Weekly downloads
 
Created
Source

Konami Code React Hook

What is it?

Allows you to useKonamiCode to listen in on any React Functional Component for the Konami Code sequence. Provide an onSuccess and onFail callback.

Eg:

import { useKonamiCode } from 'use-konami-code';
import { useState } from 'react';

const HomeComponent: React.FC<any> = () => {
    const [ message, setMessage ] = useState('');
    useKonamiCode(() => {
        setMessage('You did it!');
    }, () => {
        setMessage('');
    });

    return (
        <div>
            { message && <span>{message}</span> }
        </div>
    )
}

Custom Code Sequence

You can also provide an alternate code sequence, a String[] consisting of JavaScript Event Keycodes, as a third parameter, eg:

    const alternateKonamiCode = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a', 'b', 'a', 'Enter'];

    useKonamiCode(() => {
        setMessage('you do remember!');
    }, () => {
        setMessage('');
    }, alternateKonamiCode);

Try Keycode.info to set up your own code.

What is the Konami Code?

From Wikipedia:

The Konami Code (Japanese: コナミコマンド, Konami komando, "Konami command") is a cheat code that appears in many Konami video games, and some non-Konami games. In the original code, the player can press the following sequence of buttons on the game controller to enable a cheat or other effects:

↑ ↑ ↓ ↓ ← → ← → B A

Author

James Perih @ Four And A Half Giraffes, Ltd.

Keywords

konami

FAQs

Package last updated on 26 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.