Master React State By Solving This Problem

  Рет қаралды 1,283

Code Ryan

Code Ryan

Күн бұрын

Пікірлер: 6
@qazyhn94
@qazyhn94 3 күн бұрын
i think the reason of this: you should not do this in the fist place, its weird implementation you always expect counter to be there just with a different prop, so then render it once and change the prop instead of rendering it twice, then its obvious that prop change wont reset state (unless its implemented inside Counter component)
@theReal_WKD
@theReal_WKD 2 күн бұрын
The main takeaway here is the use of the "key" prop which basically tells React to create 2 different references for the "same" component. But you're right about the implementation, it's not optimal. I would change isPlayerA state for "player/setPlayer" which could be "A" | "B". Then just render
@qazyhn94
@qazyhn94 2 күн бұрын
@theReal_WKD exactly, but yes I was not aware of this behavior, good to know
@doby3288
@doby3288 3 күн бұрын
Nice explanation, but I was curious the whole time, about how is `Counter` component implemented.
@zshanahmad2669
@zshanahmad2669 3 күн бұрын
probably somthing like this: fun Counter(){ const [count, setCount] = useState(0); return setCount(c => c+1) } > {count} }
@doby3288
@doby3288 3 күн бұрын
@@zshanahmad2669 Yeah, something like that... I found the implementation in the provided link in the description, but thanks for the info!
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 868 М.
So, you want to be a programmer?
20:43
ForrestKnight
Рет қаралды 441 М.
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН
БОЙКАЛАР| bayGUYS | 27 шығарылым
28:49
bayGUYS
Рет қаралды 1,1 МЛН
I'VE MADE A CUTE FLYING LOLLIPOP FOR MY KID #SHORTS
0:48
A Plus School
Рет қаралды 20 МЛН
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
8 Rules For Learning to Code in 2025...and should you?
12:59
Travis Media
Рет қаралды 91 М.
React 19 is finally out!
28:01
Theo - t3․gg
Рет қаралды 70 М.
OpenAI Unveils o3! AGI ACHIEVED!
26:24
Matthew Berman
Рет қаралды 254 М.
How To Focus On The Right Problems
16:57
Y Combinator
Рет қаралды 36 М.
Devin just came to take your software job… will code for $8/hr
5:13
Run ALL Your AI Locally in Minutes (LLMs, RAG, and more)
20:19
Cole Medin
Рет қаралды 310 М.
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН