I'm going through some courses that were made before react hooks were a thing, now I'm wondering if there is any reason at all to use class-based components over functional components now that hooks exist?
I can't seem to come up with a reason or scenario where a class-based component would be preferable, but maybe I'm just not aware of certain corner-cases where a class-based component would be the go-to choice.
Appreciate any feedback regarding this.
Thanks in advance!
Class components are still used, but there is no particular reason to continue to do so. Tthe Facebook team recommends that all new React code is hook-based functional components, and not class-based. You can mix class components and hook-based components, so there is no reason to rewrite your class components.
You can read more at https://reactjs.org/docs/hooks-faq.html
The only good reason that I can think of for using class components these days would be to create error boundaries as:
Only class components can be error boundaries.
From https://reactjs.org/docs/error-boundaries.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With