Why You Need to Understand Re-rendering in React and useState Hook

Why You Need to Understand Re-rendering in React and useState Hook

Web Dev Cody

3 года назад

48,150 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@0the0ambient0
@0the0ambient0 - 31.07.2023 03:57

Very helpful explanation. Thank you.

Ответить
@stephanie446677
@stephanie446677 - 21.07.2023 03:27

Thanks for that very helpful explanation

Ответить
@Fuckthesocity
@Fuckthesocity - 27.06.2023 18:09

How to re-render using redux

Ответить
@aichakhorchani4487
@aichakhorchani4487 - 17.05.2023 11:58

Bro talking in ×3 speed what's going on? Take your time

Ответить
@qotiii
@qotiii - 16.03.2023 02:57

Finally, someone said it all in one place

Ответить
@yusker1994
@yusker1994 - 27.02.2023 00:08

You just saved my life! LOL

Ответить
@dbirkle
@dbirkle - 08.02.2023 11:03

That made my brain click, thank you very much!

Ответить
@rahalmehdiabdelaziz8121
@rahalmehdiabdelaziz8121 - 01.02.2023 00:40

Nice video, I have a problem my component rerender many time and I don't know how to track the state or props that provoque this rerendering

Ответить
@SponkADonk
@SponkADonk - 09.01.2023 17:14

Respect the drip... is all I gotta say...

Ответить
@limitless1692
@limitless1692 - 04.12.2022 18:58

When I was coding in JavaScript It was fun.
Hmm then I decided to learn React.
Ohh boy, I think React give me more headache than anything in my life. It is such a convoluted ball of "icecream" that I learned to hate!!
For the love of god, I wasted more time trying to understand React than anything, and still don' get it...

Ответить
@user-oe1tq3wn1u
@user-oe1tq3wn1u - 21.11.2022 00:49

Thank you very much, I lost 2 hours trying to make up a solution, until I found your video🙂

Ответить
@whoIsDeck
@whoIsDeck - 23.10.2022 07:06

You look different

Ответить
@IgnitionZA
@IgnitionZA - 04.10.2022 15:52

Great vid man, where you going with that backpack? Can I come? =)

Ответить
@crankk10
@crankk10 - 29.09.2022 19:02

what kind of backpack are you wearing ? or something for posture??

Ответить
@shmobeny263
@shmobeny263 - 07.09.2022 09:48

So, I have “states” of cells of minesweeper game inside their parent (let’s call it GameField). When I change state (actually props) of one of 100 cells, I need to rerender other 99. It’s kinda pain for performance.

Ответить
@zm690
@zm690 - 06.09.2022 10:59

shallow diffing ! My god !

Ответить
@niinoocode
@niinoocode - 01.09.2022 20:34

nice

Ответить
@mirzakadic9174
@mirzakadic9174 - 04.08.2022 16:48

Hi, I'm actively learning React at the moment, and one thing I would like you to answer (either here or in a video), is WHY React is better to regular JS, I understand that managing html is easier, but everything else seems so unneceserily complicated. Before this I was doing a lot of old JS for After Effects scripting (not as a pro, just needed better workflow for my AE projects), and when I compare React, just cannot figure out why is it so much better. I'm sure I'm missing some good point, but if you could elaborate, I would be grateful. thanks! Subbed.

Ответить
@tarcisiosurdi
@tarcisiosurdi - 28.07.2022 14:10

OMG I LOVE YOU I WAS ABOUT TO LOSE MY MIND OVER MY COMPONENTS NOT RERENDERING

Ответить
@firststeptowardsoursuccess
@firststeptowardsoursuccess - 22.05.2022 20:44

Thank u

Ответить
@DeKirvis
@DeKirvis - 18.05.2022 13:59

Thanks, really helpful info, shame I didnt find this video earlier.

Ответить
@tejassharma2006
@tejassharma2006 - 17.05.2022 12:57

I like your vs code mam what is it, and really help full video btw

Ответить
@akshayrawat8847
@akshayrawat8847 - 13.05.2022 14:21

Thanks a lot man , i was actually following up a tutorial and had created a lots of useStates and commented some unrequired code for HTML part but when i got into api handeling i saw a bug as component might be re rendering again and again and making multiple calls , turns out this was the reason any useState if gets updated the whole component gets re render.

Ответить
@jonoisedev
@jonoisedev - 28.04.2022 11:36

Very useful video.

Ответить
@fhkodama
@fhkodama - 08.04.2022 00:25

Hey man! You just got a new subscribed! Your video was really helpful! I can stop bang my head on the wall! :)

Ответить
@borsho9889
@borsho9889 - 18.03.2022 14:32

This was more useful than I even expected. Thank you!

Ответить
@christossotirlis2247
@christossotirlis2247 - 14.03.2022 06:03

Hey there, new to react and I kinda think I solved it in a new way. I pass the setValue as a parameter into the function that makes the change in my data. I use it in the end replacing the return. Everytime I run the function new local variables are created and of course they have different pointers in memory, so setValue rerenders properly my page. I used it in combination with fetch api. Your video helped me understand why my "hack" worked when I couldn't figure out why my code was workin

Ответить
@edkk2010
@edkk2010 - 12.03.2022 15:37

Spreading is a shallow copy though. If you have some deeply nested object, you might still run into trouble. I like to use immer to solve this problem.

Ответить
@Firex64
@Firex64 - 11.03.2022 18:08

This helped a lot. Thanks!

Ответить
@Dan_ny
@Dan_ny - 23.02.2022 20:58

When I learned react with class components this was the first thing that was known because this.state was an object. But when you see react videos with functional comps it seems that it's overlooked because the examples used is non obj/arr like a counter

Ответить
@VworksArt
@VworksArt - 15.02.2022 15:50

Thank you so much. Documentation for me is like a firehose and you distilled exactly what I needed help with.

Ответить
@aqibos
@aqibos - 11.02.2022 04:48

Really good video, thank you!

Ответить
@nightgrimalkin2745
@nightgrimalkin2745 - 07.02.2022 03:04

Thank you so much

Ответить
@shubhamh7451
@shubhamh7451 - 26.01.2022 10:34

Shit, thank you!

Ответить
@achmadakbarirwanda2658
@achmadakbarirwanda2658 - 20.01.2022 18:58

Thank you so much! Finally i understand how this works and this solved my bug.

Ответить
@deepshikha3789
@deepshikha3789 - 06.01.2022 13:44

Thanks sir. I was also not able to understand the same issue. but now its resolved .

Ответить
@jamesonvparker
@jamesonvparker - 13.12.2021 18:39

I have struggled with issue for an entire day. I thought it had to do with useContext and changing data in an object or array in context. I am about to try this as soon as I get back to my computer. Thank you for such a good explanation. I found reacts docs on dynamic context a little confusing. I hope your solution works for me.

Ответить
@michaelcasiano56
@michaelcasiano56 - 04.12.2021 17:20

great explaination.. new subscriber here.. it solved my issue with the same workaround that I have done before..

Ответить
@SR-jo2mz
@SR-jo2mz - 01.12.2021 08:19

I would like to add an another method also,
For Eg:
const[data, setData]= useState([])
=>If u want to change the setData with its state means(data)
=>Do as follows to re-render the component
setData((prevState : any)=>[...prevState])
=> By doing this It will also re-render the component with updatedData
I hope this will be useful 😃

Ответить
@AnasHmamouch
@AnasHmamouch - 18.11.2021 15:51

great content, I just discovered your channel, this is a gem!

Ответить
@nielsSavantKing
@nielsSavantKing - 12.11.2021 16:18

Why you are wearing a bag?? And you have something on your nose??

Ответить
@ulviugur3605
@ulviugur3605 - 04.11.2021 02:37

Very good explanation to a really loosely described subject. Nobody uses the term “pointer” any more with these “high-level” languages, but sometimes it is essential to use the right term, if that is exactly what happens behind the scenes. You really threw me a lifeline as I was frustrated with all the unwanted and unexpected renders. This doesn’t solve it all but I will continue with the specifics of “reconciliation” area. Thanks a lot !!! 👏👏👏🧠💪

Ответить
@sanjibdey01
@sanjibdey01 - 03.11.2021 08:21

This was insightful. Have been using new object references for state updates, but never really thought of it in this light.

Ответить
@nithipramesti2283
@nithipramesti2283 - 13.10.2021 07:04

Oh man, thank you so much for the tips!!

Ответить
@ozzyfromspace
@ozzyfromspace - 01.10.2021 18:31

You're the man! A cool video idea btw would be "actions that cause a functional component to unmount". Cheers, mate.

Ответить
@hardikpoudel3011
@hardikpoudel3011 - 02.09.2021 13:21

... syntax is called the spread syntax, just say the term, it will be easier of beginners to search and learn through the topic

Ответить
@aravindkumar8145
@aravindkumar8145 - 31.08.2021 09:41

superb video, please continue these
error solving type of videos.

Ответить
@nickpauletto2127
@nickpauletto2127 - 26.08.2021 15:46

I'd give 5 thumbs up if I could.
Been looking into the async nature of the whole thing and it was frustrating me...hacking using useEffect (that was my solution, deep down I knew it was wrong)
This now makes so much sense...it is going back to the basics, which was months ago.

Ответить
@AlejandroGarcia-ff5bz
@AlejandroGarcia-ff5bz - 13.08.2021 20:08

Great video! I wasn't sure where to ask you a question so I'm posting it here. I found a strange state update behavior that I found relevant to your solution video. If you set up a simple App like below and click the <div> the number will increase twice. I know it's happening because of a combination of using "React.StrictMode" and "useReducer", The function "App" is wrapped by <React.UseStrict> in my index.js file. Something is happening when I update the state obj property inside the reducer function. Like a double render that strict mode does but it holds the updated state and then comes back to execute the code in the reducer function. If you remove React.UseStrict and leave the code as is, it will work normally. If you leave it wrapped in strict mode and want it to work properly you have to do what you said in the video, copy the state properties to a new obj reference and return it. So instead of ( state.num++; return {...state} ) you do ( return {...state, num: state.num + 1 } ). What I don't understand is why the combination of useReducer and React.Strict cause that kind of behavior? If you don't use useReducer and use useState it will work fine. 🤷‍♂️

import React, { useReducer } from 'react';

const reducer = (state, action) => {
if (action.type === 'INCREASE') {
state.num++;
return {...state}
}
}

function App() {
const [state, dispatch] = useReducer(reducer, { text: 'Num: ', num: 1 });

return (
<div className="App">
<div onClick={() => {
dispatch({type: 'INCREASE',})
}}>{state.text + state.num}</div>
</div>
);
}

Thanks for any future insight and help!

Ответить