Loading video...

Video Failed to Load

Go Home

❌ Avoid deriving state in useEffect in React, this can create multiple unnecessary render phases. ✅ Instead derive the state directly in the event handler, this way you'll have one single render phase. ↓

39,326 views • 2 years ago •via X (Twitter)

9 Comments

George Moller's profile picture
George Moller2 years ago

I've been working professionally with React for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video animations just like this one. Check them out ↓

Web-Dev-Codi's profile picture
Web-Dev-Codi2 years ago

Informative as always. Thank you

George Moller's profile picture
George Moller2 years ago

Glad you found it informative!

NidhiSharma | React Dev's profile picture
NidhiSharma | React Dev2 years ago

Sometime overuse of useEffect cause extra re-render we should avoid useEffect where ever possible. Nice sharing.

joey finkel's profile picture
joey finkel2 years ago

But this would only work if the state that’s being updating is supposed to be updated by an event handler. For example, a piece of state you want updated on first render would still have to be the effect, right?

George Moller's profile picture
George Moller2 years ago

Do you have an example I can take a look? Unless you are fetching data or connecting to an external system first why would you need to update a state variable in first render?

Bee Network - Vietnam 🇻🇳's profile picture
Bee Network - Vietnam 🇻🇳2 years ago

great

George Moller's profile picture
George Moller2 years ago

Hey do you have an email or contact where I can send you the PP discount?

George Moller's profile picture
George Moller2 years ago

@Setback_King 😊

Related Videos