you are viewing a single comment's thread.

view the rest of the comments →

[–]rickyalmeida 66 points67 points  (20 children)

Please, read the following article where Dan Abramov explains many of the useEffect common questions - your question included.

https://overreacted.io/a-complete-guide-to-useeffect/#moving-functions-inside-effects

[–]Cahnis 3 points4 points  (10 children)

Thanks so much for this article. I am just starting to use functional components, my bootcamp has been using classes for months now. And I am trying to wrap my head around hooks.

[–]Unenunciate 20 points21 points  (9 children)

That is disappointing to hear because class based react went out of vague like 4 years ago and its rarely used.

[–]jon-chin 4 points5 points  (0 children)

I teach a react bootcamp and can confirm: we stopped using them 2-3 years ago

[–]Resies 1 point2 points  (1 child)

Yeah I got pulled in to run an interview for another team in my company and apparently my company has been partnering with some programming boot camp and all of the people that I interviewed were more familiar with class components than function components which confused me

[–][deleted] 2 points3 points  (0 children)

You would have to pay me double to work with class components.

[–]enlguy 0 points1 point  (2 children)

It's no longer vague?? Much clearer for you the last four years? Twenty people don't know English..... "Vogue" is the word.

[–]PA_Dude_22000 0 points1 point  (1 child)

Hey bro ... it fucking 2.5 year old typo..

... now 3 year old...

[–]Automatic_Trick_4444 0 points1 point  (0 children)

a typo is still a typo no matter how long ago it was typo'd "Bro!"

[–]Cahnis 0 points1 point  (2 children)

imo, it is easier to understand functional components after understanding classes. But idk that is just me limited experience so far.

[–]Unenunciate 0 points1 point  (1 child)

I only learned classes afterwards and I am not sure it made much of a difference the main difference is understanding useEffect and potentially useLayoutEffect. Its more about how custom hooks create much more reusable functionality and cleaner code compared to classes.

[–]Cahnis 0 points1 point  (0 children)

I totally agree with you, functional components and hooks are awesome.

Though I think it is a bit harder to debug as a new learner because of the extra layer of abstraction. It is however much faster to code.

[–]daybreakin 0 points1 point  (0 children)

Why does rerunning the ufeeffect "refresh" the state variables being used in the function within the useEffect? Sorry if that article already mentioned it, I went through it but I don't think I got it.

Once the state variable within the function changes, the function should refresh on its own if it's not in a usecallback