R
R
RaulDuke2021-04-01 17:35:42
React
RaulDuke, 2021-04-01 17:35:42

What is the meaning of react hooks?

Hello.

Now I am actively studying React, and as far as I understood, at some point, React developers made a sharp turn towards functional programming: stateless components, pure functions, and that's it. Someone directly, someone allegorically, but you can often hear that the class components are for the old people and retrogrades, and the functional ones are for the young, beautiful and politically literate. And so, having absorbed all these ideas, I came to a close study of hooks and did not understand why they are needed. Those. I want to say that exactly the same design is reproduced architecturally as it was with class components. Or am I missing something important?

I am especially confused by some code examples where they put useEffect into a pure function, a presentational component, and say: look how simple and cool, no OOP, only functional programming. Please explain why hooks are needed if there were already life cycle methods in class components before them? What question or developer problem does this innovation answer?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denioo, 2021-04-01
@Denioo

I am especially confused by some code examples where they put useEffect into a pure function, a presentational component, and say: look how simple and cool, no OOP, only functional programming.

Explain this first? You can throw off the code example ...
A pure function is a function that uses only the parameters passed to it, that is, it does not take anything from outside. What about useEffect?
1) Hooks make development easier.
2) The code becomes much more readable.
3) OOP shit, try to pee at least once in a functional language (for example, erlang / haskell) and now I'm not talking about js with react, and if you understand the very essence of FP, you will throw all the OOP nonsense out of your life (Java, C #, etc.). e)
4) Look at how many side effects are in the class components, and then look at how it is written on useEffect.
In general, I don’t understand what the market is about if IT technologies develop and change faster than you have time to become a Senior in some area. The only thing you need to know about hooks. Hooks are top, classes suck. In general, you were given a link to the article above, be sure to check it out.
Completely up to you. You can try hooks in some components without changing the code in others. Hooks don't have to be used or learned right now.
100% backward compatible. Hooks do not contain changes that could break your existing code.

A
Anvar Shakhmaev, 2021-04-01
@RxR

https://ru.reactjs.org/docs/hooks-intro.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question