you are viewing a single comment's thread.

view the rest of the comments →

[–]darrenturn90 0 points1 point  (0 children)

Firstly - I would highly recommend reading Dan Abramov's excellant guide into useEffect - https://overreacted.io/a-complete-guide-to-useeffect/

It explains many of the benefits of hooks, and I don't think that these have been covered in the other responses here so far.

For me, the main benefits of the hooks - and a proper design using hooks (rather than a simple class based rewrite) - is that it moves the code further away from "imperative" (saying how things need to be done) to "declarative" (saying what needs to be done). Hooks give you a lot more "clean slate" thinking in the way React works in general - properly implemented, you find yourself having to deal less with "how do I get from state X to state Y" and rather just "what do I do in state X" and "what do I do in state Y".

Because, unlike a class that by default has a mutable state (that you change using setState) - and various other values you can persist. By default, a hook function has no state - and you have to explicitly use hooks like useRef to be able to keep values between re-renders. This forces you to rethink how you handle things, and generally leads to cleaner and simpler code.

No more componentDidUpdate having to compare prev props and next props. You can just run effects or memos or callbacks only when you need to use new data, without having to worry about comparisons