awesome video ben! i'll be glad to see more videos on optimization and more advanced react concepts like this!
@PJArmy3 жыл бұрын
Great video! I was looking for complex situations and real life example and this was the only video that got close to it!
@viet.khoaiegg2 жыл бұрын
This video is actually the best on KZbin about how to use memo and even useCallback
@aleksandarbisevac31292 жыл бұрын
Wow, great example. In 10 minutes, this is the best explanation of memoisation and optimization of the react functional component. I have much better picture of useCallback and useMemo, also how to avoid writing callbacks inside React.memo. KUDOS to you Sir.
@gadayash92 жыл бұрын
Not easy to find beginner to moderate-ish vids on such topics. Might have to go through this a thousand times over a few months, but thanks man
@schnubor4 жыл бұрын
Nice! Would love to see a follow video though: "Why not use memo for all react components" ?
@marcel52354 жыл бұрын
the number of bugs you will create with this approach or time spent to actually make it work as intended + keep the app fast is something that makes you think twice about that
@maximiliaanvandijk61114 жыл бұрын
@@marcel5235 Solution.. stop using react
@codelightsparkles24033 жыл бұрын
@@maximiliaanvandijk6111 Why ? React is the king of jobs right now, other frameworks are lucky to have 50% of jobs react has. If it was me , I would have a look at Svelte for my own projects but if you meed a job then there is nothing better than react
@maximiliaanvandijk61113 жыл бұрын
@@codelightsparkles2403 Then why are you using memo. Don't think I've seen the need for that in other frameworks. Quite sure jQuery had a high job availability as well ;)
@vkj31313 жыл бұрын
@@marcel5235 to
@jayaprakashreddy5605 жыл бұрын
Awesome!! straight to the point. liked the point that how to handle the ref change of non-simple types (objects, functions) ..
@firstnamelastname46853 жыл бұрын
in 6:17 When App render , The ref to settext did change right? then how line 10 works
@PAD6373 жыл бұрын
@9:29 couldn't you also use useRef for that data object which would also prevent re-creating of the object right?
@vibekdutta65393 жыл бұрын
Ben awesome video, I had a small doubt, when u clik the increment button the Count component re-renders the state changes, but after u have wrapped the onOdd() with useCallback(), everytime you type the setText changes and it should also change the onOdd() isnt it?
@maxaquilino72644 жыл бұрын
Hey Ben good work on this as usual. It'd be great to create a video on how to optimize performance when using Flatlist applying Memo and Callback. This video explains clearly how to prevent re-rendering on functions, what about other types of components like classes. Cheers!
@EagerEggplant3 жыл бұрын
Arent classes just objects in JS?
@mr-skorpion3 жыл бұрын
Awesome vid as always Ben and thanks for flexing those vim skills 😂
@malikbrahimi75044 жыл бұрын
Why was your dependency setText for the callback? Couldn't you have left it empty? Also can you do a tutorial on using the profiler to detect optimization issues?
@scottmai74573 жыл бұрын
Amazingly clear and concise - thanks Ben!
@MohiyuddinShaikh3 жыл бұрын
Wonderful video!
@EVA_Hamza4 жыл бұрын
Amazing, we need more videos like this
@avisterdeveloper11202 жыл бұрын
Thanks crack! the only video I got that concept
@WanderlustThamur4 жыл бұрын
dude so simple and yet so clean, thank you very much!!!
@westernpigeon2 жыл бұрын
5:35 what is a lambda? tried googling but all i get is AWS Lambda and im sure they're not related
@cutipets87063 жыл бұрын
so basically useMemo used to memorize objects and useCallBack with functions? is i'm right?
@ngocdangduc3772 Жыл бұрын
I got question, Why this is not implemented by default in react ?
@chethanprabhu44753 жыл бұрын
Please someone help me. What if the parent was class based component? How can we make sure child does not rerender when we pass an function as prop to child.?
@metin4yt4 жыл бұрын
What if I have some data that's coming from a Context. That context gets updated via a WebSocket. This causes me a render on which notification. Which I guess it's fine. But I have an for each item in data, and I would like to re-render only the new items, not the old ones aswell. How can that be managed?
@rubenmartinez28073 жыл бұрын
With a memoized list item component
@md.siddiq71653 жыл бұрын
This is literally an awesome content on performance optimization in react. Thanks Ben ❤️❤️
@farizma4 жыл бұрын
Bro this is amazing, I've been struggling to understand where to use memo actually. U made it so clear ❤️❤️
@alimirazimzadeh5443 жыл бұрын
best explanation ever in 3 minutes
@darryl_young5 жыл бұрын
Thanks for sharing, Ben.
@diegounanue4 жыл бұрын
I know that child components are updated when parent is updated. But if you don't have the ref that you use in the child component, when react compares the virtual dom with the dom, what part will be uptaded in the child component? If the virtual dom of the child is the same as the dom.
@arwysyah24004 жыл бұрын
How to avoiding multiple rander if i am using flatlist in parents and passing props to Child component , while i am fetch data and assign to state,and pss props to child, it’s showing multiple rander in number of props that i passed,how to avoid that ?
@rorycawley5 жыл бұрын
Excellent video, brilliantly explained. Thanks for going to that trouble.
@carlosbenavides6704 жыл бұрын
Really nice explanation. Thanks for sharing.
@surajitdas945 жыл бұрын
Great one! Really appreciate your effort. Thanks a lot.
@mohammedg4852 жыл бұрын
thank you so much بن عوض
@abhaykumar98064 жыл бұрын
Please tell me how can I optimize redux action/state mapped as props in react components???
@marcel52354 жыл бұрын
Using reselect library which memoizes created selector. That prevents to redundant render. Actions should be triggered once in ui and ideally have controll component and dumb component, ie if u have actions that fires in useEffect have them grouped
@elie22225 жыл бұрын
What are the best tools you’ve seen to check for components rendering too much when you do run into performance issues?
@bawad5 жыл бұрын
the react profiler is pretty nice
@patrickren73954 жыл бұрын
Can I thonk of useCallback as a special version of useMemo?
@starsky4114 жыл бұрын
There is a small mistake, at 7:45, the component will NOT re-render if you return TRUE. its the opposite actually, it will re-render if you return FALSE.
@tonydanza45025 жыл бұрын
is React.useCallback() necessary for all callbacks where you are trying to avoid unneccessary rerenders of a memo-ized component? Wonder if you set onOdd equal to a plain old function expression like const onOdd = () => {setText(' ') } and ? I'm wondering why useCallback was only introduced with hooks and not before, was this optimization not available pre-hooks?
@bawad5 жыл бұрын
const onOdd = () => {setText(' ') } still creates a function each time in classes you could create methods that weren't created on each render class MyComponent { onOdd = () => {} render() { return ( ) } }
@tonydanza45025 жыл бұрын
Ben Awad gotcha, thanks so much!
@nicofraisse83804 жыл бұрын
What color scheme are you using? Looks really nice
@benjaminhobson20853 жыл бұрын
Brilliant man. Thanks.
@hanggianggono37655 жыл бұрын
Thank you BEN AWAD
@Mr.QLead1417 Жыл бұрын
react says that if you have "expensive component" or "massive rerenders in a second" then you should use "memo". If there isnt any lag or smth, they say it is OK. So, because of the old PureComponent approach, everybody puts memo to every functional component. Because they didnt want to rerender the functional component. But, if the component arent expensive and it is not rerendering simultaneously (for example onResize or coordinates changing events), then shouldn't we just leave the component without memo? There are a lot of discussion about this topic, and such this videos, new react developers may get confused or make misusages about memo. What do you think about ? I think a more important topic is deciding whether a component is expensive or not. When to use "memo" and do we need performance optimization here or not ?
@GoeHybrid5 жыл бұрын
This is awesome! Thank you!
@23sagunjaiswal234 жыл бұрын
best video found after 2 days of trying to understand this
@jordiyaputra83593 жыл бұрын
You saved my code, thank you
@jooooo95723 жыл бұрын
thank you for great content
@tonydanza45025 жыл бұрын
is there a good strategy for memoizing a component that is passed a prop that is a complex object, like an array of objects that you'd get back from an API?
@bawad5 жыл бұрын
Does the complex object change often?
@tonydanza45025 жыл бұрын
Ben Awad no
@bawad5 жыл бұрын
then the reference to the object should stay the same and memoizing should work
@tonydanza45025 жыл бұрын
@@bawad sorry I mispoke what was actually happening, though physically they look the same, the objects are definitely different. What I am doing is setting an interval every 10 seconds to get information back from an api and then rehydrating the state with what I get back. Is there a technique for reducing rerenders when a shallow comparison is not enough?
@tonydanza45025 жыл бұрын
I guess I could handle this situation another way, when i setState every time that interval is executed I could check to see if the objects have changed, otherwise don't set state. I wonder if that's best practice?
@AnNguyen-uv9yc2 жыл бұрын
amazing bro
@alanson763 жыл бұрын
Awesome, Thanks a lot!!!
@huynhut53955 жыл бұрын
I tried with string, number, boolean, array, object, function and result was: not-rerender: string, number, boolean rerender: array, object, function And i used useMemo with Array similar to Object but it's re-render? Can you help me!
@bawad5 жыл бұрын
the reference to the array, object, function is changing each render then
@naseer0362 жыл бұрын
Very good content
@ChavitaRocha5 жыл бұрын
Hi Ben! I was curios about What keyboard do you use? :P Thanks for your videos :)
@bawad5 жыл бұрын
das keyboard
@abhaykumar98064 жыл бұрын
Why is my renders.current value double the count in React.StrictMode?? Any idea....
@chass88624 жыл бұрын
i had the same issue
@chass88624 жыл бұрын
i believe strict mode is used to find side effects and in order to help you do this is invokes methods such as render twice rather than once like react would normally
@Chocoholic13375 жыл бұрын
Hey Ben! I've learned about a really wicked extension for VSCode - it's called IntelliCode. It adds suggested autocomplete based on "AI" (Basically they scanned a ton of repositories). So for instance: const string = "potato"; string. - will show .split, .replace, .toLowerCase. But if I do if (string.){} it will show .length, .indexOf, .,match etc. Look into it, I think it's cool!
@bawad5 жыл бұрын
cool, I'll check it out
@planetmall25 жыл бұрын
Great example!
@Daniol5 жыл бұрын
Can you say what's the name of this font?
@bawad5 жыл бұрын
dm
@nuiatsun5 жыл бұрын
dank.sh/
@arturgaik47774 жыл бұрын
thanks dude!
@muratasarslan23594 жыл бұрын
Wonderful !
@deshario3 жыл бұрын
Wanna some examples with graphql useQuery[apollo-client lib]
@hardikchawla49664 жыл бұрын
You are the best !!
@amershboul91073 жыл бұрын
very useful
@user-ke2on2ju8m4 жыл бұрын
thank u so much!
@Givemilesrewardmiles5 жыл бұрын
can you please do a similar video but without using hooks?
@elie22225 жыл бұрын
Miles Rostami look at React.purecomponent, add functions to the class and not in render, and look at shouldcomponentupdate to the same sort of thing with older versions of React using classes
@bawad5 жыл бұрын
kzbin.info/www/bejne/l6nToZ2ln9GIpNk
@uusa354 жыл бұрын
thank you
@modestas28905 жыл бұрын
Are you using vim?
@bawad5 жыл бұрын
Yes
@D4MJ4NTTK5 жыл бұрын
brilliant
@budiprakosa69845 жыл бұрын
thanks!
@miguel9000302 жыл бұрын
You literally saved my ass
@krillkusb58873 жыл бұрын
helpful
@rtorcato5 жыл бұрын
Problem really is that people build massive components that do too much. In this demo it would be way easier to just build an input component that handles it's own state on change.
@bawad5 жыл бұрын
yes and no, sometimes you need to raise the state
@js_programmer84232 жыл бұрын
I am so confused, it seems like React.memo, useMemo & useCallback all do the same exact thing, fml.