Why do we need our own hooks?

So far, you have seen the usage of official React hooks. Hooks cover many common use cases for you to manage the state and the side effects in React components. However, do not stop there.

If an application needs the same stateful logic in two different places, it is a good idea to extract this code into your own hook. By doing so, you can share any stateful logic as a standalone module that can be tested on its own, shared, and reused.

Custom hooks can take any number of input arguments and return anything just to suit your needs. This is another awesome benefit to owning hooks. In addition, you are not limited to returning an object, an array of objects, or even another function.

Get hands-on with 1200+ tech skills courses.