The important things to know about React state and renders

  Рет қаралды 27,740

Web Dev Cody

Web Dev Cody

Күн бұрын

A walkthrough on react state and when react re-renders components
My VSCode Extensions:
- theme: material community high contrast
- fonts: Menlo, Monaco, 'Courier New', monospace
- errors: Error Lens
- extra git help: Git Lens
- tailwind css intellisense
- indent rainbow
- material icon theme
- prettier & eslint
- ES7+ React Snippets
------------
🤑 Patreon / webdevjunkie
🔔 Newsletter eepurl.com/hnderP
💬 Discord / discord
📁. GitHub github.com/cod...

Пікірлер: 55
@WebDevCody
@WebDevCody 2 жыл бұрын
idk why I kept saying "because of how closures work". there are no closures here, just scoping. "because of how scoping works". cheers!
@KWerder92
@KWerder92 2 жыл бұрын
phew, I was already doubting myself 😛
@doc8527
@doc8527 2 жыл бұрын
Frontend interview question is another trouble maker, they asked a lot of code cases (terrible object reassignment patterns and abuse variable scope) that you should never use them in code, and then ask you what happen if you use them, some ignorant devs even are pretentious about knowing those non-sense. It cause many Devs to hard memorize them. In fact, you should never know them, they will pollute your knowledge database.
@sprioleau
@sprioleau 2 жыл бұрын
I've been writing React for a few years now and though I know how state works for the most past, you filled in some gaps for me in this single video. Well said. This was helpful! I love your videos and tune in as often as I can.
@katadermaro
@katadermaro Жыл бұрын
the audio quality of this video is amazingly done, delight for my speakers! Great video. Thanks.
@unknown-user001
@unknown-user001 2 жыл бұрын
this is the explanation that I've wanted for a long time. Most of the tutorials explain how hooks work and how not to use them, but those never explain this much. Thanx.
@alireda-re1ce
@alireda-re1ce Жыл бұрын
Absolutely fantastic video which is absolutely necessary for anyone looking to get into react to watch. Understanding the concepts here really saves so much debugging time. I know because I suffered debugging these kinds of issues for so long lol😅
@pesterenan
@pesterenan 2 жыл бұрын
That was really useful! I'm refactoring code from other people that is really full of states and variables, so this will help me decide what to keep and what to change.
@Goyo_MGC
@Goyo_MGC 2 жыл бұрын
Great video to remember the concepts behind React ! I've been so immersed in the framework that i was going with the 'everything needs to be a state' mindset. But when a re-render is not needed it is true that you can use generic JS which i forgot ! I might have to update my linters to allow it from time to time ^_^
@alexstrasza4938
@alexstrasza4938 4 ай бұрын
thank you, you're very good at explaining
@returncode0000
@returncode0000 2 жыл бұрын
Jesus christ, I finally understood how useState works haha thanks! Please, do an example like this with all the other standard hooks, this would be so fricken awesome. You are so talented in explaning things!
@WebDevCody
@WebDevCody 2 жыл бұрын
Thanks man I appreciate that. Yeah maybe useEffect next
@returncode0000
@returncode0000 2 жыл бұрын
@@WebDevCody This would be awesome, thanks 😊
@mahmoudtaleb8281
@mahmoudtaleb8281 Жыл бұрын
Just wonderful!
@randomorigins5041
@randomorigins5041 2 жыл бұрын
Thanks!
@yasuke1280
@yasuke1280 2 жыл бұрын
The last 5 minutes of this video was too intense for my brain. I was keeping up until then, time to save this in my watch later.😅
@NazariyMurall
@NazariyMurall 2 жыл бұрын
Really good job, short and extremely helpful 💪💪💪
@spiridonov1
@spiridonov1 2 жыл бұрын
awesome video and really unique way of demonstrating it
@AtmaniChouaib
@AtmaniChouaib 11 ай бұрын
thank you you made it really clear and simple
@itsmepawan
@itsmepawan Жыл бұрын
Amazing video, subbed 🥂
@rohil3023
@rohil3023 2 жыл бұрын
A very useful video for us beginners!
@jonathanyngfors3905
@jonathanyngfors3905 Жыл бұрын
Great! Thanks
@thomas-gk9jp
@thomas-gk9jp 2 жыл бұрын
Thank you so much !!
@AsakuraAvan
@AsakuraAvan Жыл бұрын
lol 'Shadow DOM', that sounds badass. React should've called it that instead of Virtual DOM
@WebDevCody
@WebDevCody Жыл бұрын
There is a shadow dom concept, I just confused the terms 😔 google shadow dom vs virtual dom
@matthewrossee
@matthewrossee 9 ай бұрын
17:02 state setters are fully synchronous
@user-dl7mn3ti9u
@user-dl7mn3ti9u 2 жыл бұрын
Loved the tutorial man this thing is legit 100% !! althogh i wish if theres a way you can do it on computer
@WebDevCody
@WebDevCody 2 жыл бұрын
Do it on a computer? What do you mean
@emmanuellmiqueletti7029
@emmanuellmiqueletti7029 Жыл бұрын
I got this question for a senior dev interview. The interview wants a detailed explanation why react renders
@kishorjanjal7454
@kishorjanjal7454 2 жыл бұрын
thanks much needed explanation
@doc8527
@doc8527 2 жыл бұрын
I think one of the important issue with React is that many newbies expect React works as JavaScript. It's apparently not. This is actually a common Frontend issue nowadays, many jump into the Frontend world with one framework like react, svelte, or vue and etc. without knowing the fundamental of JavaScript, even the JavaScript itself has a lot of clucky behavior, so they will make a lot of mistakes at the beginning. The worse case, they want to apply framework philosophy everywhere even back to language itself. if you have something in your code like a dependency state update as a learner, there might be something wrong in your code most likely ``` setAState(newA); // waiting A update, something happen in between, setBState(A); ``` Just a common trouble pattern I see in React, Svelte and Vue also have their own issues to deal with.
@WebDevCody
@WebDevCody 2 жыл бұрын
Solid js tries to avoid this problem by always requiring a function for getting the current value of state. But yes to truly understand these react state bugs you need to know js pretty well
@thecutedreamkostasp.4449
@thecutedreamkostasp.4449 2 жыл бұрын
This guy is literally Broken!
@WebDevCody
@WebDevCody 2 жыл бұрын
I’ve lost my mind
@alekxandar
@alekxandar 2 жыл бұрын
This is really usefull, Thank you
@ihateorangecat
@ihateorangecat 6 ай бұрын
This is the 1k th like for this video. 999 to 1k
@zakarianaji9428
@zakarianaji9428 2 жыл бұрын
thanks for the video
@vizunaldth
@vizunaldth 2 жыл бұрын
Pretty sure closures have more to do with functions “closing” over inner state with an inner function doing something with that state. Would definitely say that’s much more global state as it’ll be available on window object as scoped.
@WebDevCody
@WebDevCody 2 жыл бұрын
Yeah true bad word choice, it’s more of how scoping works, no retakes. Record once and publish 😂
@vizunaldth
@vizunaldth 2 жыл бұрын
Respect for you doing it tho!
@Paxters_
@Paxters_ 2 жыл бұрын
great video!
@crystalcacik3346
@crystalcacik3346 9 ай бұрын
nice :)
@SeibertSwirl
@SeibertSwirl 2 жыл бұрын
Good job love ❤️
@justine_chang39
@justine_chang39 2 жыл бұрын
i love using Vue, and I think it's far superior to React, but it just doesn't have the same quality libraries like React does. Even component libraries aren't as good as the ones in React-land, the most popular 2, Vuetify and Quasar, are styled with Material UI, which is soooooooo ugly in 2022. I COULD use Tailwind, but I don't want to design all my components from scratch. Lemme know if you know any beautiful Vue 3 component libraries!
@lindennerdhh
@lindennerdhh 2 жыл бұрын
I think that if you we're to make your count vanriable const, then js wouldnt hoist it anymore, but you would have to do some hacky stuff to change it. Great video! Love your didactics
@alexanderkalchev188
@alexanderkalchev188 2 жыл бұрын
I have a question about useEffect. Why should fetch data from an API inside useEffect and not just inside the component function?
@WebDevCody
@WebDevCody 2 жыл бұрын
Because the component function will rerun over and over again
@masiafmasiaf2204
@masiafmasiaf2204 2 жыл бұрын
in your example to put the count var (min 5:18) outside the component and you can mutate it, is there a different with useRef? like a countRef.current and change it from there?
@WebDevCody
@WebDevCody 2 жыл бұрын
useRef will not tell React to re-render. But yes, you could use a ref and increment it, but you'd still need a useState somewhere to let react know it's time to render again.
@masiafmasiaf2204
@masiafmasiaf2204 2 жыл бұрын
@@WebDevCody thanks for the answer i didnt know is there has a difference on useRef, cause i had some issues using it, wanna save some var on a useRef cause i know that var is not gonna show on screen, but for some reason the value on the useRef change, when a use the debugger it just go to that line of useRef and the value change just like that, i end up doing the other way that a forgot was a old sprint that i have had and there was no answer on stack overflow or google. it i encounter the same problem i will sure let you know.
@garrysyt8461
@garrysyt8461 2 жыл бұрын
Amazing to know what happens under the hood
@smrpkrl
@smrpkrl Жыл бұрын
4:33
@okandikkulak8057
@okandikkulak8057 Жыл бұрын
13:54
@coldym
@coldym 2 жыл бұрын
Did you mean to useMemo in 14:31 ?
@WebDevCody
@WebDevCody 2 жыл бұрын
Yes, typed the wrong thing. React.memo is for components
Turning bad React code into senior React code
13:10
Cosden Solutions
Рет қаралды 90 М.
3D Environment MasterClass VOL. 3 | DETAIL is Photorealism
3:58:56
pwnisher
Рет қаралды 1,2 МЛН
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 16 МЛН
So Cute 🥰
00:17
dednahype
Рет қаралды 59 МЛН
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 63 МЛН
How React ACTUALLY works (DEEP DIVE 2023)
12:59
FrontStart
Рет қаралды 60 М.
Preventing React re-renders with composition
12:11
Developer Way
Рет қаралды 20 М.
Understanding React's UI Rendering Process
29:07
CrossComm, Inc.
Рет қаралды 215 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 643 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 476 М.
This is when testing in software starts to suck
20:22
Web Dev Cody
Рет қаралды 9 М.
Do this before you deploy to Vercel
20:28
Web Dev Cody
Рет қаралды 25 М.
Combining Zustand with React Query
20:24
Cosden Solutions
Рет қаралды 17 М.
UseState: Asynchronous or what?
17:00
Jack Herrington
Рет қаралды 65 М.
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 16 МЛН