A FUNNY IDENTIFIER OF WHAT A HOOK IS In ReactJS

So, what exactly is a hook? I once asked a friend of mine to give me examples of hooks in React, then she went ahead and said “are they not those things that start with USE something, like useEffect, useState, etc”, I could not help but laugh at her response, and honestly for a while I identified them as that too.

So the idea behind the design of React hooks was so that we can make reusable codes work, just the same way we do with regular Javascript functions, where we write a function that can be called and used anywhere by just passing in arguments.

The reason behind the consistent naming with a “USE” is as a result of the naming convention that the React team speculated.

Just as we have the already existing hooks, we can write our own hooks that suit our use-case and this is called a CUSTOM HOOK, it is basically writing a function that uses other hooks inside it. For instance, if we want to write a Hook to get an item from the local storage every time a page loads (meaning we would make use of the useEffect Hook ), deserialize it then displays the item on the screen, also it saves an item in the local storage when a particular state changes (useState Hook). Then we will probably name this Custom hook a useLocalStorage().

So the moment of truth, this is my first time ever writing an article, I always tried to understand how people just pick a pen and write and it turns into an article or a book and this was a thing that discouraged me for a long time, “the fear of what if what I write doesn’t make sense” or “what if people make jest of my writing” then I learned recently that first of all no one is born with the skill, everyone who writes today started by just picking a pen to write something, and over time they get better, and here I am saying I overcame that fear and this is just the start.

Thank you for reading, I hope you were able to get a better understanding of what a hook and custom hook means