Easter eggs using Rooks

I stumbled upon this great React Hooks library called Rooks recently and it has got a lot to offer. We all have discovered various Easter eggs in various apps and sites. It can range anywhere from stumbling upon a Rick-roll when you click a button a ce…


This content originally appeared on DEV Community and was authored by Anish De

I stumbled upon this great React Hooks library called Rooks recently and it has got a lot to offer. We all have discovered various Easter eggs in various apps and sites. It can range anywhere from stumbling upon a Rick-roll when you click a button a certain number of times or enjoying playing snake when you press a hidden button on a 404 page.

Ok, so let us start making an Easter egg ?

An alert when you press a certain key combination

Rooks provides us with a very useful useKeys hook. With this, we can trigger an action whenever a certain key combination is pressed. For this example whenever the keys Q, W, E, R, T, and Y are pressed, all together, an alert will be triggered saying the key combination was pressed. This is a simple example and hence a great place to start

Firstly we need to create a react project (you can use Gatsby, NextJS, etc as well as long as it is React). I am using Codesandbox for this tutorial but you can do it locally as well.

Now we need to install rooks so we can run

npm i - s rooks

You can following the getting started guide for rooks.

Now let us see the code

Firstly, we need to import the hook:

import { useKeys } from "rooks";

Now we need to configure the hook:

useKeys(["KeyQ", "KeyW", "KeyE", "KeyR", "KeyT", "KeyY"], () => {
    alert("QWERTY");
});

Here, the first parameter is an array of all the keys that need to be pressed. We pass in a callback function which will be triggered if all the keys are pressed as the second parameter.

Now whenever the 6 keys are pressed together, we will see this alert -

image.png

Codesandbox -

Now we have successfully made our first Easter egg ?!!!

Now it is time for you to explore other hooks and come up with some great Easter eggs for your site.

Feel free to share your creations down in the comments section.


This content originally appeared on DEV Community and was authored by Anish De


Print Share Comment Cite Upload Translate Updates
APA

Anish De | Sciencx (2021-09-12T09:05:00+00:00) Easter eggs using Rooks. Retrieved from https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/

MLA
" » Easter eggs using Rooks." Anish De | Sciencx - Sunday September 12, 2021, https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/
HARVARD
Anish De | Sciencx Sunday September 12, 2021 » Easter eggs using Rooks., viewed ,<https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/>
VANCOUVER
Anish De | Sciencx - » Easter eggs using Rooks. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/
CHICAGO
" » Easter eggs using Rooks." Anish De | Sciencx - Accessed . https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/
IEEE
" » Easter eggs using Rooks." Anish De | Sciencx [Online]. Available: https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/. [Accessed: ]
rf:citation
» Easter eggs using Rooks | Anish De | Sciencx | https://www.scien.cx/2021/09/12/easter-eggs-using-rooks/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.