DEV Community

Discussion on: Constructors in Functional Components With Hooks

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Interesting/related note: This article has quietly gathered more views than anything else I've written. Unlike most of my articles, that have a certain "splash" for a few days - and then are rarely read again - this article continues to get a steady stream of traffic.

What's the point?? Well, it would seem that there are a lot of other people out there who are switching to Hooks, then saying, "Wait a minute. How do I create a constructor with Hook??", then they start googling and end up on my article. (And there seems to be very few other articles out there on the same topic.)

So while it may indeed be "ugliness", I surmise that there are many others who are confused/annoyed by the (FALSE) idea that you can simply use useEffect() to replace all of the previous lifecycle methods, and there's no logical reason to use the constructor functionality that we had in class-based components.

Thread Thread
 
alexvukov profile image
alex-vukov

Thank you for writing this article! I thought I was missing something by always having to skip renders with a flag which is set only after a fetch is started in useEffect or trying to do fetch calls in something like your constructor. Seems that React devs have missed the point that sometimes you need to have a cause before you can handle the effect...

Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

Having spent years working with the lifecycle methods that are available in class-based components, I'll be the first to tell you that they can, at times, cause major headaches. But the Hooks team seems to have decided that the way to cure the headache is to cut off the head.