Custom Hooks

Custom hooks are a great way to avoid repeating yourself while writing code. Custom hooks will always use a primitive React hook. Its not for JSX.
Each hook should have only one purpose, such as data-fetching from a specific api.

Steps to take when creating reusable hooks

  1. Identify each line of code related to some single purpose
  2. Identify the inputs to that code
  3. Identify the outputs to that code
  4. Extract all the code into a seperate function, recieving the inputs as arguments and returning the outputs.

Sentence to keep in mind when writing custom hooks:

If you give me a
….

I will give you

For example:

If you give me a (input)
default search term
I will give you (output)
a way to search for videos and a list of videos.

Add your comment