Answer the question
In order to leave comments, you need to log in
What is the point of using hooks?
Hello, I don't understand what's going on.
There were classes, there were HOCs, components were divided into Container/Component or Smart and Stupid.
They had their own areas of responsibility, nothing was mixed up, but then hooks appeared.
And if you can only live with React hooks, but when the project is not a demo, but a real one, then a bunch of different libraries are connected, every second one has hooks, in the end everything is mixed up.
Further, the philosophy of Redux, "do not dispatch actions directly", everything through actions creator and so on and so forth, now we are simply provided dispatch
from useDispatch()
Now the component is firmly connected with the redux, and is responsible for everything at once.
How to test it?
Will we have to create a wrapper from the provider for the test of each component?
Previously, you could take a component, pass in props, and be happy.
As a result, I don’t understand where everything is going, why do they leave classes (convenient, understandable, structured) for functional components with hooks?
On demo examples, everything is clear and obvious - the components are simpler and more readable on hooks, but real projects are some kind of mess and stuffing
Answer the question
In order to leave comments, you need to log in
There were classes, there were HOCs
components are separated into Container/Component or Smart and Stupid
And if you can only live with React hooks, but when the project is not a demo, but a real one, then a bunch of different libraries are connected, every second one has hooks, in the end everything is mixed up.
Further the philosophy of Redux, "do not directly dispatch actions", everything through actions creator and so on and so forth, now we are simply provided with dispatch from useDispatch()
Previously, you could take a component, pass in props, and be happy.
As a result, I don’t understand where everything is going, why do they leave classes (convenient, understandable, structured) for functional components with hooks?
Just more features, you can build more flexible applications, more accurately adjust the architecture, shoot yourself in the foot (head, liver) more accurately.
No one forces you to shove useDispatch everywhere, you can still connect your containers to the redux and enjoy the clean architecture.
As they say, everything is in your hands. If the application is very crutch, then the classes will not help here either.
To be honest, I have never had any experience in writing class components. I always wrote only in functional ones and I actively use hooks.
The code of functional components is much simpler, smaller and clearer, IMHO. Hooks are very useful tools. You need to have separate state. Something goes to redux, something is stored directly in the state of the component itself. It also depends on the approach to organizing the structure in the project.
useState, useRef and useEffect - in general, I use it in every project, I can’t imagine how one can do without this trio. The use of the rest depends on the tasks.
Will we have to create a wrapper from the provider for the test of each component?
Previously, you could take a component, pass in props, and be happy.
On demo examples, everything is clear and obvious - the components are simpler and more readable on hooks, but real projects are some kind of mess and stuffing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question