HACKER Q&A
📣 nassimsoftware

Should I stick to Class based React or learn Hooks?


What's your opinion?


  👤 6r0k Accepted Answer ✓
It would be in your best interest to at least _learn_ hooks, since they are gaining popularity and are the presumed future of React [0]:

> In the longer term, we expect Hooks to be the primary way people write React components.

I also recommend learning the differences between function components (the prerequisite of hooks) and class-based components. This way you can gain understanding into why one would want to use one over the other which will ultimately serve you better than simply learning something just for the sake of learning it. "How Are Function Components Different from Classes?" [1] by Dan Abramov is a great start.

[0] https://reactjs.org/docs/hooks-faq.html#should-i-use-hooks-c...

[1] https://overreacted.io/how-are-function-components-different...

Edit: formatting (every time...)


👤 proc0
You can do both. Hooks are easy to learn. The class components could be lower level (page/dom components), while the ones using hooks would be functional, composable components on the edge of the tree (last things to render).

👤 joshxyz
IMO Classes are great for learning the lifecycle, Hooks are great for reducing the code size.