DEV Community

Discussion on: Constructors in Functional Components With Hooks

Collapse
 
jackmellis profile image
Jack • Edited

I often face the same issue but it is easily solved with a useRef. I usually write a useEagerEffect hook that runs before rendering, but still only runs when the deps array changes.

The part I really agree with, though, is how react's docs (and those of many other libraries) make these sweeping assumptions that nobody could ever possibly need anything outside of their perceived use cases. The blind arrogance you mention really frustrates me!

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

You're spot-on about the useRef. In fact, in my useConstructor NPM package, I wrote it with useRef, rather than the useState approached illustrated in the article. There was another commenter on this thread that was gracious enough to point me in that direction.