J
J
jsdev12020-08-04 16:22:39
React
jsdev1, 2020-08-04 16:22:39

Should You Use Hooks in React Redux?

I read the documentation about using React Hooks in react-redux.
Hooks in comparison with the usual connect function, the code looks much more complicated.
In many places, code is written to compare equality, and the documentation itself refers to third-party libraries, five hooks are used instead of one, and so on.
It seems to me, or is a regular connect easier and more convenient compared to hooks?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kotik Meow, 2020-08-04
@AlexVais

Hooks look complicated at first glance, but they actually simplify the code. Instead of a state in the constructor, it is more convenient to use useState (in fact, splitting one state into several). useEffect makes lifecycle methods easier to work with. The same can be said for other hooks (useContext, useRef, etc.). We can also get rid of various wrappers in applications instead of using connect using useDispatch and useSelector (for redax). It is also very convenient to use hooks in react router (useHistory, useParams). Well, and probably the most important thing is that we ourselves can write our own hooks, which allows us to do cool things (for example, checking 3 captchas with a hook). I have been writing on hooks for a year now and have never been disappointed in them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question