React hooks are a new addition to the React library. They provide a way to add functionality to react components that previously would only be possible if one used classes. For example, adding state. You had to use classes in these cases. Function components could only be pure components as a result. Not so anymore.

Why hooks? You might ask. According to the react team, hooks were introduced to solve a number of issues. Some of these are listed below:

  • Wrapper hell - when you have to nest too many components
  • Huge components - contain a lot of code and logic making it hard to refactor.
  • Confusing classes - having to deal with the peculiarities of JavaScript classes i.e this keyword and binding.
  • Unneccesary code duplication
  • Avoiding bugs