Saturday, October 19, 2019

Why do we need React Hooks?

What are hooks

You go to any react session in 2019 or look at any sample on React, you get a word how cool hooks are? Hooks has slowly graduated from hippies & enthusiasts to all. There's only one reason it's talked so much. Because "It makes sense"


Like any new solution, there will be issues and we'll talk about them as we work on more samples, but on the whole, hooks has given React community a unique experience that makes us feel(proud) better as developers.

Why now?

So far we've used different ways to create React components. createClass and/or ES6 classes. Although things have improved with time, some of the fundamentals have taken a down turn and got more complicated. Before we delve into answers, let's talk about a fundamental reason React came to serve this market - "Easy, simple and reusable components".

With time, additional baggage web technology brought in, made React some what convoluted. React engineering had to go back to their boards and re-engineer some of their thoughts and concepts to achieve and stay focussed on the primary objective.


  • Handling state within a component
  • Life cycle events for a component
  • Separate visual elements from non-visual one's (service invocations from UI)
  • Better integration with other solutions like MobX, Redux etc
Anyone who worked on React long enough would either feel overwhelmed with 13.x & later or feel everything is fine, why change? Either ways, you'd start to look at what hooks bring to table, you'll see your code get a lot better and much more manageable, as opposed to writing less re-usable components or building more HOC.


Different types of Hooks


In addition, we can create our own custom hooks that are more re-usable. Not to forget, we also have other libraries like Redux that come with their own hooks. Yes, HOOKS EVERYWHERE!

No comments: