React Hooks useMemo Tutorial

  Рет қаралды 78,766

Ben Awad

Ben Awad

Күн бұрын

Пікірлер
@StephenRayner
@StephenRayner 5 жыл бұрын
Clearly spoken, well structured, to the point, no umming and arring... These videos are fantastic.
@adeoyeadela
@adeoyeadela 4 жыл бұрын
Wow I have spent more than 48hrs solving a problem with re-rendering but the last 5 minutes of this video saved my ass... :) thanks Ben
@gustavolsilvano
@gustavolsilvano 5 жыл бұрын
You're awesome! This is one of the best react channels on youtube
@bawad
@bawad 5 жыл бұрын
Thank you!
@dasnipa520
@dasnipa520 5 жыл бұрын
wow this is extremely helpful, thank you my inner coding god
@trentmiles5616
@trentmiles5616 3 жыл бұрын
Dunno if anyone cares but if you guys are bored like me during the covid times you can stream all of the latest movies and series on instaflixxer. Have been watching with my gf for the last couple of months :)
@kobeshepard9776
@kobeshepard9776 3 жыл бұрын
@Trent Miles yup, I have been watching on InstaFlixxer for months myself :)
@WrongAkram
@WrongAkram 5 жыл бұрын
You are awesome, thanks for making these types of videos!
@thisisgksingh
@thisisgksingh 3 жыл бұрын
Amazing tutorial on useMomo hook. Thanks for this Ben.
@WaterJay
@WaterJay 5 жыл бұрын
I start to think react might be going down a road of over complexity things. In order to do efficient rendering, u have to watch out all sorts of performance pitfall, considering react memo, usecallback, usememo along the way and pick the right dependency. This wouldn’t even be a problem if u you only change/update the value where it has been changed instead of do a freaking diff and render at any chance it get. Used to be react fan btw, now I’m thinking what’s the point and all these starts to get silly. All of a sudden, reactive programming looks charming
@DiegoJutsu
@DiegoJutsu 4 жыл бұрын
You are not alone
@xerxius5446
@xerxius5446 4 жыл бұрын
I love this hooks series. Thanks for the videos !
@neelakshsharma4936
@neelakshsharma4936 4 жыл бұрын
Amazing stuff. After reading the hooks docs, if I don't get what it tries to convey, I refer these videos and it pretty clearly.
@Kr00kan
@Kr00kan 2 жыл бұрын
Straight to the point. Great video Ben!
@Oxcorp
@Oxcorp 5 жыл бұрын
A way you can find the largest word in an array is with the Array.reduce() method, here's how I did it: const longestWord = ['some', 'words'].reduce((biggest, curr) => { return curr.length > biggest.length ? curr : biggest }
@EndiFreeKolesio
@EndiFreeKolesio 5 жыл бұрын
It can get even easier with Array.find ;)
@converter
@converter 5 жыл бұрын
this is not algorithm channel :P ofcourse there's different ways to do that
@nikosspiropoulos8417
@nikosspiropoulos8417 4 жыл бұрын
great video!!! explains a lot about both useCallback AND useMemo !!!
@markdesign1354
@markdesign1354 5 жыл бұрын
Great video! Quick Question: Isn't this same as calling computeLongestWord inside useEffect and setting longestword with useState?
@bawad
@bawad 5 жыл бұрын
kind of, that would cause a rerender though
@markdesign1354
@markdesign1354 5 жыл бұрын
@@bawad I just did a quick test, seems to behave the same for me. Am I missing something? codesandbox.io/s/react-hooks-usememo-example-lowde
@bawad
@bawad 5 жыл бұрын
yeah they would have similar behavior but calling the setter in useEffect would cause another render
@markdesign1354
@markdesign1354 5 жыл бұрын
@@bawad ah!.. got it. after I put a console.log outside computeLongestWord(), I can see the extra render without useMemo ! Interesting.., computeLongestWord() is still only called once in both scenarios, so performance seems to be negligible. Thanks for helping me understand it finally !!!
@joracardanovsky4192
@joracardanovsky4192 5 жыл бұрын
I'm not sure why would you specify the function itself in the use memo second parameter. In which case would that be useful? By the way, thanks for your videos, extremely useful
@shabeebck3057
@shabeebck3057 4 жыл бұрын
So basically useMemo is using to execute a function when a change value of its given dependency, thats amazing !
@AntiMassovka
@AntiMassovka 4 жыл бұрын
Nice, bro. Like the way you code. Thanks for the info!
@matijatu
@matijatu 4 жыл бұрын
I'm wondering if there is a reason why the unmount is inside of a separate useEffect. I'm talking about useFetch @ 1:50
@alecs6326
@alecs6326 5 жыл бұрын
Great channel thanks for the awesome content!
@harishp9686
@harishp9686 5 жыл бұрын
Thanks for awesome contents... could you please create a video on setting monorepo with cra and typescript?
@bawad
@bawad 5 жыл бұрын
sure
@harishp9686
@harishp9686 5 жыл бұрын
@@bawad also please include redux
@markovujanic
@markovujanic 4 жыл бұрын
Thanks Ben, this is really useful in context explanation.
@rediculiqi4136
@rediculiqi4136 4 жыл бұрын
This was very helpful for me , please make some more of those , with optimization performance topics
@jamesjohnson5386
@jamesjohnson5386 5 жыл бұрын
Is there any reason why you put setState in a dependency array for useEffect?
@bawad
@bawad 5 жыл бұрын
because if setState changes, I want to use the new value inside useEffect though setState is unlikely to change
@florian_206
@florian_206 5 жыл бұрын
@@bawad it will not change. "React guarantees that setState function identity is stable and won’t change on re-renders. This is why it’s safe to omit from the useEffect or useCallback dependency list." reactjs.org/docs/hooks-reference.html#usestate
@andrewking1173
@andrewking1173 4 жыл бұрын
Thank you for these!! Needed these for work :D
@MrDevianceh
@MrDevianceh 5 жыл бұрын
Just wanted to say, i love the hooks series :) Maybe cover creating custom hooks and things like that :)
@bawad
@bawad 5 жыл бұрын
Any particular custom hook you'd like to see made?
@jora5483
@jora5483 2 жыл бұрын
absolutely brain-melting!!
@dhruvilpatel856
@dhruvilpatel856 4 жыл бұрын
@Ben Awad, Can we put computeLongestWord function inside useMemo (just above we call it) instead of putting it outside of component? (The point is to avoid passing as dependency)
@bawad
@bawad 4 жыл бұрын
> The point is to avoid passing as dependency What do you mean by that? Putting it outside the component would allow you to avoid passing it as a dep
@dhruvilpatel856
@dhruvilpatel856 4 жыл бұрын
@@bawad what if in situations where we want to export this component, does putting the function outside of it still work?
@bawad
@bawad 4 жыл бұрын
Yeah
@colloidalsilver177
@colloidalsilver177 5 жыл бұрын
This was awesome but where did “arr” come from?
@bawad
@bawad 5 жыл бұрын
it's the parameter github.com/benawad/react-hooks-tutorial/blob/4a5200a39a9b06a1df9ee6afd68153a47ed847af/src/App.js#L4
@BobbyBundlez
@BobbyBundlez 3 жыл бұрын
@@bawad lolz
@ivanbadyulya5562
@ivanbadyulya5562 5 жыл бұрын
What is the extension you use for block context underline?
@bawad
@bawad 5 жыл бұрын
I'm actually not sure what is causing that. Here are my settings though benawad.com/plugins
@tunvirrahman9504
@tunvirrahman9504 3 жыл бұрын
how to test "ComputeLongestWord"?
@Isha3006
@Isha3006 5 жыл бұрын
Could you please show, How we could use useMemo() with async await
@bawad
@bawad 5 жыл бұрын
I wouldn't, I would pick useEffect for that
@AshishRawat-zl6te
@AshishRawat-zl6te 4 жыл бұрын
Really amazing work Man. Just a suggestion- It would be good if u give the link to a code sandbox or codepen.io for the code, which would be really helpful for ur subscribers.
@stevereid636
@stevereid636 5 жыл бұрын
Eslint now complains that computeLongestWord is not a valid dependency in useMemo when employing your recommended solution of relocating the function outside?
@bawad
@bawad 5 жыл бұрын
does eslint want you to do: useMemo(() => computeLongestWord(data), [data, computeLongestWord])
@stevereid636
@stevereid636 5 жыл бұрын
@@bawad Not when computeLongestWord is located outside the App. It does like it being a dependency of useMemo when it's outside
@stevereid636
@stevereid636 5 жыл бұрын
@@bawad Here's the message: function computeLongestWord(arr: any): string | any[] React Hook useMemo has an unnecessary dependency: 'computeLongestWord'. Either exclude it or remove the dependency array. Outer scope values like 'computeLongestWord' aren't valid dependencies because mutating them doesn't re-render the component.eslint(react-hooks/exhaustive-deps)
@bawad
@bawad 5 жыл бұрын
oh, just remove computeLongestWord from the dep list useMemo(() => computeLongestWord(data), [data])
@stevereid636
@stevereid636 5 жыл бұрын
@@bawad It's just that you say in the video that computeLongestWord should be in the dep list?
@alocer1
@alocer1 5 жыл бұрын
.json url was dead. found another copy here raw.githubusercontent.com/ajzbc/kanye.rest/quotes/quotes.json
@trungnguyen5947
@trungnguyen5947 4 жыл бұрын
Another way to find the longest word: function computeLongestWord(data) { if (!data) { return []; } const longestWord = JSON.parse(data) .map((sentence) => sentence.split(' ')) .reduce((prevValue, currValue) => [...prevValue, ...currValue]) .reduce((longest, curr) => (curr.length > longest.length ? curr : longest)); return longestWord; }
@__greg__
@__greg__ 4 жыл бұрын
Very helpful, thanks!
@costeachitorog5322
@costeachitorog5322 5 жыл бұрын
thanks man
@stealthysubie
@stealthysubie 4 жыл бұрын
You're the best man!
@alexey9796
@alexey9796 5 жыл бұрын
Thanks, but you should return an empty string not an empty array
@bawad
@bawad 5 жыл бұрын
Why
@alexey9796
@alexey9796 5 жыл бұрын
Ben Awad I was texting about the computeLongestWord function. Why the positive results is a string, but if there isn’t data - it’s an array? I see types inconsistency in this case
@bawad
@bawad 5 жыл бұрын
oh I see, yeah idk why I did that your right empty string makes more sense
@touradhadrami6530
@touradhadrami6530 Жыл бұрын
@vipulchodankar62
@vipulchodankar62 4 жыл бұрын
Nice.
@lardosian
@lardosian 4 жыл бұрын
Kanye Rest lol!!!
@PouyaAtaei
@PouyaAtaei 5 жыл бұрын
Hey mate, great material. But just slow down, chill, and explain in good harmony. I can see that you're definitely a good practitioner, but when it comes to teaching, well, it's far away from getting there.... a good example of a coding teacher can be Stephen Grider on Udemy... typing so fast and going through things so quickly doesn't make it cool, it just makes it stressful.
@bawad
@bawad 5 жыл бұрын
Thanks for the feedback
@ElTopoYoutuber
@ElTopoYoutuber 3 жыл бұрын
&
React Hooks useReducer Tutorial
17:16
Ben Awad
Рет қаралды 91 М.
React Hooks useEffect Tutorial
20:15
Ben Awad
Рет қаралды 157 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
React Hooks useCallback Tutorial
11:15
Ben Awad
Рет қаралды 115 М.
Learn useMemo In 10 Minutes
10:42
Web Dev Simplified
Рет қаралды 494 М.
React.memo, useMemo, and useCallback Optimizations
22:09
Code Bushi
Рет қаралды 44 М.
10 React Hooks Explained // Plus Build your own from Scratch
13:15
Fireship
Рет қаралды 1,4 МЛН
React Hooks useLayoutEffect Tutorial
10:22
Ben Awad
Рет қаралды 44 М.
How I Made a Game in React Native
12:01
Ben Awad
Рет қаралды 48 М.
Actix Web vs. Axum: Is One a Clear Winner?
8:59
OptiCode
Рет қаралды 2,5 М.
How to Roll Your Own Auth
13:05
Ben Awad
Рет қаралды 124 М.