Hey @bytebodger
I am new to hooks, I previously only used components where I used to rely on the constructor. I wonder if I'm doing it right... since I really miss the constructor functionality, I created two hooks: useCreateOnce (returns a value) and useRunOnce.
But now I'm using these 2 in many places so I wonder if there isn't another way, which follows more React hooks "intended" philosophy? Or maybe I shouldn't worry that much?
This article right here on Dev.to is pretty handy - so much so that I stuck it in my reading list. A constructor is ultimately a lifecycle method. And in Hooks, there is exactly one lifecycle method - useEffect(). As the name implies, there is no such thing as a useEffect() call that runs before the component renders (since, an "effect" has to happen... after something else). And as the article above implies, useEffect() can actually be used four different ways - although I don't personally believe that any of them are intuitive just by reading the names/arguments.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey @bytebodger I am new to hooks, I previously only used components where I used to rely on the constructor. I wonder if I'm doing it right... since I really miss the constructor functionality, I created two hooks: useCreateOnce (returns a value) and useRunOnce.
But now I'm using these 2 in many places so I wonder if there isn't another way, which follows more React hooks "intended" philosophy? Or maybe I shouldn't worry that much?
dev.to/spukas/4-ways-to-useeffect-pf6
This article right here on Dev.to is pretty handy - so much so that I stuck it in my reading list. A constructor is ultimately a lifecycle method. And in Hooks, there is exactly one lifecycle method -
useEffect()
. As the name implies, there is no such thing as auseEffect()
call that runs before the component renders (since, an "effect" has to happen... after something else). And as the article above implies,useEffect()
can actually be used four different ways - although I don't personally believe that any of them are intuitive just by reading the names/arguments.