Why i won't use React Hooks

・1 min read

I'm passionate about ReactJS, because of its declarative programming model.

That means, in React,

view = function(state)

That's why i never mess React Component with side-effects, like ajax request or state.

With separate function for behaviour, you can easily reuse, unit test, and package it.

With React Hooks, what i have to do is to mess side-effects within the component.

It's not good to me.
It's not simple to debug.
It's not simple to reuse the behaviour.
It's not easy to unit test the behaviour.

That's why i would say NO to React hooks, because i prefer simplicity to magic.
I'm a simple developer, not a magician trying to understand wtf is going on with my production code.

DISCUSS (12)
 

I can understand your concerns. Though at the same time, hooks are just an upgrade for the lifecycle functions of class components or the HOC's, but they make it simpler, so if you used those, there's no reason you shouldn't use hooks. I find that hooks look clearer than HOC's or lifecycle functions (HOC's would just always confuse me when I have to compose them, especially when I'd try to create props typings).

I get though that you want to keep your components as much functional as possible. Personally, I started separating my components into containers and views. Views have nothing async, zero side effects, just props => ReactElement. All the data loading and state management and side effects happen in containers. Even when I switch to hooks, it will stay that way.

 

Today I found a good use case for react hooks. I needed a way to execute a function every 10 seconds. So, I used a custom hook called useInterval, which can be found on npm as “use-interval”. Works super well. Just pass it a function and the delay and bang. After the component unmounts the interval clears 😊

 

I didn't get familiar with hooks, but it seems React team is sometimes pushing it too far, the need to innovate, and the question remains, whether there was really a need for it, or not.

 
 

That's why i never mess React Component with side-effects, like ajax request or state.

How do you do it then?

 

You can use a HOC (Higher order component) to reuse behaviour, or using Render Props pattern.

 
 

Totally agree with. I also posted a question against it.

 

Yet you have a post on 'A React Hook for universal routing' xD
yeah seems like React team is stretching it too far with react hooks . not a fan YET :)

 

Yeah, i was wrong at the time of the post. I comeback and retry and i was hooked :P

Classic DEV Post from Dec 7 '18

What is a type of "overconfidence" you have observed in developers?

There are certainly a lot of ways developers can be "underconfident" in the for...

I hate technical debts, very much. Learning to clean debt out of my life.