Avoid this React State Mistake | React Previous State Explained

preview_player
Показать описание

In this tutorial, React Previous State is explained. I will also explain why using setState with count + 1 is NOT wrong... but updating previous state in React requires an understanding of how state and re-rendering work together.

Avoid this React State Mistake | React Previous State Explained

(00:00) Intro
(00:05) count + 1 is NOT wrong
(01:12) Know when to use the right tool
(01:28) The Golden Rule
(02:09) Previous State function example
(03:05) Why prefer the prevState function
(07:28) Previous state with arrays
(10:03) Previous state with objects
(12:06) Summary

🔗 ES7 React JS Snippets Extension for VS Code:

🔗 React Dev Tools Extension for Chrome:

📚 References:

✅ Follow Me:

Was this tutorial about understanding Previous State in React helpful? If so, please share. Let me know your thoughts in the comments.

#react #previous #state
Рекомендации по теме
Комментарии
Автор

The key phrase that explained everything "React updates state in batches". One another fantastic explanation from Dave. Thanks again!

carsugarmodels
Автор

wow, i'm all the way from Malaysia, watched this video and thought to myself "finally, something i always was confused about, explained to me easily". Thank you soso much :)

tankashing
Автор

exactly the lecture i needed. incredible! i saw the exact same docs in reacts website and still could not understand when to use the previous state.

GabrielMartinez-ezue
Автор

Updating the state using previous value did tricked me for a moment as I wasn't aware of it,
it's hard to forget what was learned from a mistake (my life story 🤦‍♂️)
Thanks for the update Dave,

ahmad-murery
Автор

Thank you Dave ! you helped me having a better understanding of states in React

funnyway
Автор

Done thanks
Always use the version of state setter that takes the previous value because just setting the state without taking previous value doesn’t behave properly

mostinho
Автор

Nice explanation Dave, this is definitely one of those state pitfalls that tend to confuse beginners.

caffeinated-pixels
Автор

That helped clarify a few important notions. Thank you!

stillsmart
Автор

Thank you so much for this clear explanation, you are a hero! Needed previous state for adding items to an array and got it working immediately after watching your tutorial 👏🥳

annemieknieboer
Автор

Good lesson. Thank you. I'm trying to understand the lessons from the first lesson. Sometimes it is hard to get it but the next lessons seem very easy.

jamshidtashkent
Автор

Great video, helped clear misconceptions with state. Cheers.

avidambassador
Автор

Thanks for clarifying how state update works, Dave.

matinsasan
Автор

Thank you that was very detailed and helpful

ohmygoodness
Автор

How the same, This simple awesome explanation .Gray You are Great !!

cuberos
Автор

perfect content, thank you a lot for sharing knowledges

oussemabouyahia
Автор

thank you soo much dave. Great Explanation!

houseofcoding
Автор

Dave you just saved my demo. God bless

jackiefranken
Автор

nice explanation ... but i was looking for the answer to WHY .. WHY and HOW prev state does what it does and WHY the currvalue doesnt work

nos-
Автор

Thank you so much, Know I understand how prevState works

umeshpalsingh
Автор

Hey, first I just saw your playlists and they look great. I plan to watch all the videos available, but I was wondering, after learning react what's the point of using vanilla JS in projects instead of react?

Bskater