Learn useMemo In 10 Minutes

Learn useMemo In 10 Minutes

Web Dev Simplified

4 года назад

495,018 Просмотров

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


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

@elhaambasheerch7058
@elhaambasheerch7058 - 08.04.2023 15:35

The amount of clarity Kyle gives while explaining complex concepts is truly unmatched, certainly my go to channel to learn tough concepts.

Ответить
@RishitGahlaut
@RishitGahlaut - 11.04.2023 08:57

thanks bro ,, I understand very well ..

Ответить
@by-Murat
@by-Murat - 13.04.2023 23:06

thats great, first example and second explain the issue great way. After first one , I told myself hah what is the different between useEffect and useMemo then I got answer :D In that way as far as understand if use useEffect with array or object it is useless and we have to use useMemo ?

Ответить
@billwu7367
@billwu7367 - 20.04.2023 09:23

you are a skillful and smart ,patient youngster

Ответить
@ralphstube
@ralphstube - 24.04.2023 14:10

To make the 'slowFunction' slow the console.log needs to go inside the for loop:

function slowFunction(num) {
for (let i = 0; i <= 5000; i++) {
console.log("Calling Slow Function");
}
return num * 2;
}

otherwise it's just counting, which isn't noticably slow.
I was staring at it for ages, thinking "this isn't really slow" - take the count way down, try 1,000 and gradually increase.

Ответить
@skandarsouissi7282
@skandarsouissi7282 - 30.04.2023 02:18

Can you link react hooks to their docs in the blog that would be very useful, thanks <3

Ответить
@abdulmuneebafridi4437
@abdulmuneebafridi4437 - 12.05.2023 13:48

Appreciate your effort , well thanks for providing effective content

Ответить
@timelapsegeek
@timelapsegeek - 01.06.2023 13:39

perfectly explained

Ответить
@jamjam3448
@jamjam3448 - 01.06.2023 20:22

nice hair

Ответить
@AmanMavi1
@AmanMavi1 - 19.06.2023 09:35

watching your video before i got the job, watching ur video after i got the job

Ответить
@karim6179
@karim6179 - 22.06.2023 05:36

i literally been searching in udemy for a course that explain react hooks like this saw couple of videos but none of theme get to that great content quality feels guilty to get that for free thanks man

Ответить
@alan208
@alan208 - 27.06.2023 12:56

W teacher

Ответить
@Switchfusiontech
@Switchfusiontech - 27.06.2023 19:17

Please how effective would it be to use useEffect to fetch data from an api with an empty dependency array and use useMemo to watch for change and update accordingly, I would like to know if this practice would work and how effective it would be as I have my useEffect rerendering endlessly anytime I put the state of the response in its dependency array

Ответить
@tylermorris84
@tylermorris84 - 29.06.2023 03:25

Edzack ... edzackly ... edzack values.... is that how he's spelling it?

Ответить
@krils9984
@krils9984 - 02.07.2023 06:31

Thank you so much. I'm doing a project for my school and you just saved me my ass!

Ответить
@devDive615
@devDive615 - 17.07.2023 17:33

oooh that was the best explanation i've seen so far

Ответить
@ErShikharChauhan
@ErShikharChauhan - 22.07.2023 21:41

how easily u make things make sense 👏

Ответить
@soumyaranjan1433
@soumyaranjan1433 - 29.07.2023 17:27

Honestly I use test exact code , but not see any changes

Ответить
@Popc1007
@Popc1007 - 30.07.2023 18:37

Great video

Ответить
@LEGnewTube
@LEGnewTube - 01.08.2023 16:11

Clear as crystal. Thank you for the vid!

Ответить
@Samuel-sc9qi
@Samuel-sc9qi - 02.08.2023 14:32

Correct me if I'm wrong:
'useMemo' return every time new 'themeStyles' object -> every time 'dark' changes new 'themeStyles' object is created -> You can move 'useMemo' dependencies to 'useEffect' without any useMemo needed.

I understand that dependencies can be confusing without 'useMemo', but in this app it's correct to use:
const themeStyles = {
backgroundColor: dark ? 'black' : 'white',
color: dark ? 'white' : 'black'
}
useEffect(() => {
console.log('Theme Changed')
}, [dark])

Ответить
@cordial
@cordial - 13.08.2023 18:09

In the second example, couldn't you just use a useEffect on the dark useState?

Ответить
@RafalStefanowicz
@RafalStefanowicz - 14.09.2023 07:00

great job

Ответить
@abnow1998
@abnow1998 - 22.09.2023 21:53

Dude, I have been watching your videos from past 1-2 yrs, Y don't you dump your entire courses on Pluralsight or Udemy man!! It's worth the pay.

Ответить
@miggu
@miggu - 30.09.2023 16:45

it's also important to note that if you need a calculation to run once, instead of using useMemo you could put the function in the argument of another useState, and save it there. As this is also a performance technique

Ответить
@amitd1927
@amitd1927 - 02.11.2023 10:51

Howz it different from useEffect, as useEffect we can only run when certain value change.

Ответить
@ViktorHugo-je6rq
@ViktorHugo-je6rq - 17.12.2023 21:02

Thanks Kyle for explanation.
Separate thanks for your clear english.
It's easy to hear and to understand each word you say.

Ответить
@-anonim-3008
@-anonim-3008 - 19.01.2024 12:09

Ohh, thank so much! I watched you video 3 month ago and didn't understand second case, but now you open my eyes! Thanks a lot!

Ответить
@nishant_singh
@nishant_singh - 20.01.2024 08:31

Was this that easy ? Thanks Adrian...!

Ответить
@waleed28ful1
@waleed28ful1 - 06.02.2024 21:25

Thankyou soo much for these amazing videos i thought i know react and I hate JS but no now i realise that i hate JS even more than i knew🥹

Ответить
@viktoriiapetrova5801
@viktoriiapetrova5801 - 10.02.2024 13:15

Bravo! Great explanation!

Ответить
@AB-dp7pw
@AB-dp7pw - 15.02.2024 08:27

Great video kyle!

Ответить
@ThomasPGeorgeCSB-
@ThomasPGeorgeCSB- - 29.02.2024 13:29

This was the best example to understand useMemo. Thanks a lot!

Ответить
@johnmoore4248
@johnmoore4248 - 04.04.2024 21:48

In the original program, will the slow function aka doubleNumber is still triggered if it is not called in return.

Ответить
@goranqaqnass5867
@goranqaqnass5867 - 16.04.2024 23:12

nice explanation thanks

Ответить
@petartrajkovski465
@petartrajkovski465 - 19.04.2024 20:02

so the code will work the same if I use useEffect, what is the difference ?

Ответить
@shanmathinaidu5375
@shanmathinaidu5375 - 17.06.2024 19:58

in first case where useMemo is used to wrap slow function so that it runs only when number changes, why dont we use useEffect for that

Ответить
@nitinkadam8588
@nitinkadam8588 - 02.07.2024 14:58

Key Differences
- useMemo is used to memoize values.
- useCallback is used to memoize functions.

Usage:
- Use useMemo when you have a computation that you want to avoid recalculating unless necessary.
- Expensive calculations that don’t need to be recalculated every render.
- Derived state that involves costly processing.
- Large lists or data sets that require processing before rendering.
- Passing objects or arrays as props to prevent unnecessary re-renders of child components.
- Complex dependency arrays in hooks.
- Use useCallback when you have a function that you want to avoid recreating unless necessary.

Return Value:
- useMemo returns the result of the computation.
- useCallback returns the memoized function.

Ответить
@muhammadnoman3955
@muhammadnoman3955 - 13.07.2024 14:24

Couldn't understand referential equality concept 😢

Ответить
@ObjectiveTruth-zm3hi
@ObjectiveTruth-zm3hi - 24.08.2024 05:00

what is the difference between onClick={()=> setDark(prevDark => !prevDark)} and onClick={()=> setDark(!dark)} ? ?

Ответить
@anna-booklove
@anna-booklove - 27.09.2024 09:19

That was great! I really finally understood it! :3

Ответить
@jmg9509
@jmg9509 - 01.10.2024 17:20

Man this man is so gorgeous, it's ridiculous.

Ответить
@sangdilbiswal30
@sangdilbiswal30 - 24.10.2024 12:51

bro your explanations are insane

Ответить
@RejetiMeghaVardhan
@RejetiMeghaVardhan - 15.11.2024 13:32

Thank you Kyle! for giving such clarity in explanation

Ответить
@talhakhan4684
@talhakhan4684 - 30.12.2024 16:15

state updates in react cause re-renders. Sometimes in our component, we might have some code that takes some time to evaluate and we don't want that code to evaluate with every re-render if it is not going to make any difference. So we use the useMemo hook which prevents that time-consuming code from re-executing with every re-render. useMemo allows us to pass a dependency array to it and this way the code inside useMemo runs only when a dependency changes. useMemo stores the return value of the cb function we pass to it and returns that value from memory if the dependency hasn't changed.

Ответить