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
- Identify each line of code related to some single purpose
- Identify the inputs to that code
- Identify the outputs to that code
- 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
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.