Learn useCallback In 8 Minutes

  Рет қаралды 445,982

Web Dev Simplified

Web Dev Simplified

Күн бұрын

🚨 IMPORTANT:
Full React Course: courses.webdevsimplified.com/...
In this video I cover everything you need to know about the useCallback hook. I go over all the main use cases for useCallback as well as many common mistakes that developers make. This is part of a series of React videos where I cover all the important hooks in React.
📚 Materials/References:
useCallback Blog Article: blog.webdevsimplified.com/202...
React Hooks Playlist: • React Hooks
🧠 Concepts Covered:
- How to use hooks in React
- How to manage referential equality of functions in React
- How to use the useCallback hook
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#ReactJs #WDS #useCallback

Пікірлер: 259
@nanonkay5669
@nanonkay5669 4 жыл бұрын
useMemo: Returns and stores the calculated value of a function in a variable useCallBack: Returns and stores the actual function itself in a variable
@GuitarreroDaniel
@GuitarreroDaniel 3 жыл бұрын
Thanks man!
@h2o313
@h2o313 3 жыл бұрын
good summary. I often found "useCallBack" is handy when you're passing the parent's setState function down to its children.
@Vishal-ki2df
@Vishal-ki2df 3 жыл бұрын
Why can't we use useEffect instead of useCallback?
@vijaykumarreddyalavala3713
@vijaykumarreddyalavala3713 3 жыл бұрын
@@Vishal-ki2df Using useEffect you can run a function when a variable changes. But that does not mean that function will not run when the other state variables in your component change. Using useCallback you can make sure that the function runs exactly when you want it to run based on changes in a variable instead of everytime the whole component renders.
@ParadoxWorks
@ParadoxWorks 3 жыл бұрын
@@vijaykumarreddyalavala3713 Freaking nicely explained
@pawandeore6989
@pawandeore6989 Жыл бұрын
for someone who is confused the main difference between useMemo and useCallback is usMemo cache values and useCallback caches the function itself
@pawandeore6989
@pawandeore6989 2 ай бұрын
@@xlgnepoTechnically, you can achieve a similar effect by using useMemo to memoize a function, but it's not semantically the same as using useCallback. useCallback is specifically designed to memoize functions to ensure stable identities across renders, which is crucial for performance optimizations, especially when passing functions as props to child components. It's more explicit and conveys the intention more clearly. So while useMemo can be used for this purpose, useCallback is the recommended approach for memoizing functions in React components.
@tomaszkapalka
@tomaszkapalka 2 жыл бұрын
I am always impressed how you can explain quite complicated things in a simple way! As always...great job and many thanks!
@davidserranoii4114
@davidserranoii4114 4 жыл бұрын
Your understanding is inspirational. The biggest take away from this video im getting is to look behind the scenes to improve your code so you can run as efficiently as possible. Always look forward to your videos
@oracleking4252
@oracleking4252 Ай бұрын
I love this guy. He breaks it down!!!! Wherever I am, whatever mess I am in, I look for him to solve me problems. He's my personal full stack overflow
@Shoulon
@Shoulon 3 жыл бұрын
This is really awesome. I was building a grid that was initially built from a function then would set it to state. But my other components would force it to rebuild everytime. UseCallback fixed this issue!
@hamzafaysal909
@hamzafaysal909 3 жыл бұрын
Just watched your useMemo video and I was really confused between these 2 hooks but this video clears everything... Thanks Kyle : )
@stevereid636
@stevereid636 2 жыл бұрын
This is awesome. I’ve been wondering about the differences for ages. I feel like Kyle just granted me a super power 😎
@markwillis1045
@markwillis1045 3 жыл бұрын
Ha, I’m so glad I found this channel. I’m going to be busy watching these the next few days! 😀
@sottitron
@sottitron 3 жыл бұрын
Enjoying your hooks videos. Your video has a function passed into a component. It makes me think I'd really like to see a course or series on solving some of the trickier design problems with React. Specifically, concepts I've caught myself getting tripped up in my thinking with are: How to decide to use props, state or a store/reducer (and when to use context.) Strategies for interacting with APIs. When passing a function to a component makes sense. Testing your components when you're using hooks.
@mohmarroun3189
@mohmarroun3189 Жыл бұрын
Thanks , I am always impressed how you can explain quite complicated things in a simple way 👍👍
@simeonieroteev4555
@simeonieroteev4555 3 жыл бұрын
That explanation is very, very clear and useful! Thank you!
@zdargahi
@zdargahi 2 жыл бұрын
you explain difficult concepts so clear and simple. Web Dev simplified, indeed
@borisnekezov6620
@borisnekezov6620 2 жыл бұрын
Thanks for that video, Kyle! The best and simplest way to understand useCallback!
@angell2341
@angell2341 3 жыл бұрын
Explaining the usecase on why we have to use that is really ausum, I felt ur channel unique
@tadeuszjiwu255
@tadeuszjiwu255 3 жыл бұрын
This is a very clear explanation, thank you very much, keep up the good work
@aryanshmahato
@aryanshmahato 4 жыл бұрын
Desktop in introduction was looking dope! Great video BTW..
@GrigorMinasyan
@GrigorMinasyan 3 жыл бұрын
So helpful! I had an issue where socket connection would get duplicated when toggling dark more
@marcelotorreblanca9276
@marcelotorreblanca9276 2 жыл бұрын
I've been having a really bad time looking at the React documention about those hooks. And just when I was wondering about the difference between useMemo and useCallback: Boom!! you read my mind!! Just outstanding explanation!!!
@andrewshaban2888
@andrewshaban2888 Жыл бұрын
You are a good tutor. This is a rare talent. Thank you very much!
@KaaiSpeaksHisMind
@KaaiSpeaksHisMind 2 жыл бұрын
Beautifully explained, thank you.
@johnhaupenthal
@johnhaupenthal 3 жыл бұрын
Clear and concise, great video.
@davidgentilli7944
@davidgentilli7944 3 жыл бұрын
Thank you, Kyle. This explanation is incredibly clear and easy to understand.
@frontendHacks
@frontendHacks 2 жыл бұрын
watch useCallback Hook in Hindi in easy way explained kzbin.info/www/bejne/fZuZaaWEZdt_icU&ab_channel=Front-EndHacks
@mrnabby4178
@mrnabby4178 Жыл бұрын
The topic is crystal clear. Thank you man.
@developerbuddyavikunj5996
@developerbuddyavikunj5996 2 жыл бұрын
It was really helpful 🤗🙏 . Thanks alot for sharing. Finally got clarity on the concept.
@logio7663
@logio7663 3 жыл бұрын
Very clear explanation. Thanks a lot ! !
@markwillis2336
@markwillis2336 2 жыл бұрын
OooF! This is just pure gold. You just helped me out of a hole again Kyle, thank you so much!
@simmzzzz
@simmzzzz 5 ай бұрын
Best tuts on the web - PERIOD. Thanks Kyle!
@shivanyachandra4214
@shivanyachandra4214 3 жыл бұрын
Great video!! can you make a separate based on the difference between useMemo and useCallback, this will really be helpful!
@jaytran247
@jaytran247 3 жыл бұрын
Super genius explanation. Thanks so much.
@bek3634
@bek3634 Жыл бұрын
really simple explanation! thanks to you a lot.
@thebetoxpro
@thebetoxpro 2 жыл бұрын
Amazing explanation. Thank you from Mexico
@derekmoore7401
@derekmoore7401 3 жыл бұрын
very helpful and succinct. Thanks for your videos!
@VishalSharma-rn7mt
@VishalSharma-rn7mt 3 жыл бұрын
awesome tutorial, when I will have money, I will definitely buy your course brother
@NITESHSINGHNRS
@NITESHSINGHNRS 3 жыл бұрын
bro....your explanation is to diff from others and have more details. keep it up.. superb
@maor44
@maor44 2 жыл бұрын
Amazing work man! thank you!
@iurii7752
@iurii7752 4 жыл бұрын
Great explanation :) Thank you
@davidhahn7391
@davidhahn7391 3 жыл бұрын
great explanation! thank you.
@johannesperez9548
@johannesperez9548 Жыл бұрын
Crystal Clear, thank you so much!
@keiferramos8858
@keiferramos8858 2 жыл бұрын
very true. You really simplified it.Good Job😌.
@luaneaquino7835
@luaneaquino7835 3 жыл бұрын
Thank you! great tutorial
@Karlponken
@Karlponken Жыл бұрын
Great explanation! Thanks a lot!
@ifillup
@ifillup 4 жыл бұрын
Great explanation (again)!
@rileykarl4895
@rileykarl4895 2 жыл бұрын
You and net ninja is a killer combo - thank for the great vids !
@HOLONIA4EVER
@HOLONIA4EVER 3 жыл бұрын
Amazing explanation !
@mayankvora8116
@mayankvora8116 3 жыл бұрын
Awesome Explanation
@hoyinli7462
@hoyinli7462 2 жыл бұрын
super clear. highly recommend this channel :)
@vivarantx
@vivarantx 2 жыл бұрын
great man, you deserve great success
@eshwarravikanti7659
@eshwarravikanti7659 3 жыл бұрын
Great explanation!!!!! More power to you:)
@larcho
@larcho 9 ай бұрын
Awesome video. There quite a few videos here in youtube that explains this poorly, thanks for this.
@rohith8269
@rohith8269 9 ай бұрын
Great explanation!
@lightrao
@lightrao Жыл бұрын
Thank you, very useful !
@shizasiddiqui1689
@shizasiddiqui1689 3 жыл бұрын
You're brilliant Kyle.
@Wakkyguy
@Wakkyguy 4 жыл бұрын
It would be very helpful if you could make a useMemo() vs useCallback() video demonstrating their practical usage in one sample project.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I have a blog post linked in the description which does a good job of comparing them to each other.
@Wakkyguy
@Wakkyguy 4 жыл бұрын
@@WebDevSimplified Yes I have read that. Just wanted to see them being used in a single project.
@guidoglielmi7992
@guidoglielmi7992 2 жыл бұрын
lt bugs me that useMemo(()=> ()=> [number, number + 1, number + 2]) would be the same as using useCallback
@GreatAdib
@GreatAdib Жыл бұрын
it can be used in search feature just use debounce an pass it to useCallback.
@jnmldo
@jnmldo 6 ай бұрын
Thank you so much for this video
@jefersoncosta2621
@jefersoncosta2621 2 жыл бұрын
awesome!! U rock, thank you so much for this video.
@ibrahimyoussef4489
@ibrahimyoussef4489 Жыл бұрын
Wow!!! awesome I swear this lesson the real best lesson off all I get in this point and this always you
@shane2023amazon
@shane2023amazon 3 жыл бұрын
concise and helpful
@lakshyaagarwal4044
@lakshyaagarwal4044 3 жыл бұрын
what a wonderful example !!!
@manishkumartripathi2259
@manishkumartripathi2259 Жыл бұрын
Nice explanation 😊
@nihadyaqublu2359
@nihadyaqublu2359 Жыл бұрын
thank you for the video!
@Stef-an
@Stef-an 2 жыл бұрын
These short videos are life-savers for juniors. Thanks a lot!
@COROLOSTO
@COROLOSTO Жыл бұрын
And mids :p, oh wait, that means that I'm not mid lvl? oh man! :(
@saarza9991
@saarza9991 3 күн бұрын
​@@COROLOSTO we all are noobie poobies :)
@naserpapi8921
@naserpapi8921 Жыл бұрын
Excellent Thanks
@neisservilla7239
@neisservilla7239 3 жыл бұрын
thanks you really help me
@eldowado
@eldowado Жыл бұрын
Hey man - love these videos, you seem to have one on every concept. I **think** I can throw you some suggestions to make your audio even crisper, without changing your hardware at all. If you're interested, we can give it a go - then I can maybe ask you some React questions in return, haha. Be well, mate!😁
@kwaku_2023
@kwaku_2023 2 жыл бұрын
You are a blessing!
@sergiyrudenko905
@sergiyrudenko905 3 жыл бұрын
you da best, bro!!! thanks!!!
@xylvnking
@xylvnking Жыл бұрын
this one gave me a lot of trouble for some reason despite the other hooks not being too tough. the way i wrapped my brain around it is to remember that useCallback allows us to pass a reference to a function, whereas passing a regular function as a prop causes react to create a new function within the component on each render. useMemo allows us to avoid expensive variable calculations, and useCallback allows us to avoid redundant functions being created in memory. if I'm wrong PLEASE let me know lol
@nishaindesilva3738
@nishaindesilva3738 Жыл бұрын
thanks! this solve a major confusion in react. I always wondered why inner functional component resets on parental state update. the answer is useCallback() !
@thecutedreamkostasp.4449
@thecutedreamkostasp.4449 2 жыл бұрын
Excellent show case of usecallback! But i wanted to mention that u could avoid usecallback there if u just out the function outside the App Component and just pass the number as argument on it! Then every time App component rerenders the function wouldn't generated again! Big loves for your channel!
@mohammadsaadati2863
@mohammadsaadati2863 2 жыл бұрын
Tnx very useful
@AnoJlJloH
@AnoJlJloH 3 жыл бұрын
You're the BEST!!!
@yag7769
@yag7769 3 жыл бұрын
Amazing, thankss
@prince5922
@prince5922 Жыл бұрын
6:19 You can pass parameters using useMemo, from react documentation, the following. useCallback(fn, deps) is equivalent to useMemo((yourParameters) => fn, deps).
@bibahbibah5108
@bibahbibah5108 2 жыл бұрын
really u have simpleified to me
@cyberwolf9543
@cyberwolf9543 Жыл бұрын
I got this BRO )) THANKS TO YOU!!! AFTER 2 YEARS NOTHING CHANGED ABOUT USECALLBACK BRO?
@ritavdas7570
@ritavdas7570 Жыл бұрын
Amazing video
@blakelarson5005
@blakelarson5005 3 жыл бұрын
Great video
@sudhansupradhan6891
@sudhansupradhan6891 3 жыл бұрын
Awesome 👌
@Bruno-ds8ze
@Bruno-ds8ze 4 жыл бұрын
finally thankyou very much
@lemon_maho
@lemon_maho Жыл бұрын
Mannnn I was actually going to search for a solution to my problem, and then without me even searching, I see this video and I'm like : sure let's check it, just for it be the solution I'm looking for, now I'm off to use that in my code, thank you ^^
@vinzbrain
@vinzbrain 2 жыл бұрын
Great video! 2 questions: 1) wouldn't it not make more sense to pass the generated array to List rather than the function that generates them? 2) can useCallback be achieved with useMemo that that wraps a function that returns a function?
@rajk1623
@rajk1623 2 жыл бұрын
I like the second question, I wonder the same.
@rahuldwivedi4758
@rahuldwivedi4758 5 ай бұрын
Great work. But here’s the issue. The useEffect wouldn’t be called again in your List component as you have mentioned. But whatever inside your return is, will be re-rendered again. Put a console log inside the return block of list component to see. To prevent that you need to wrap the List component with memo, memo(List)
@goharamin820
@goharamin820 3 жыл бұрын
thank you soo much
@tinmank
@tinmank 3 жыл бұрын
Hello, are you planning to make a simple login sample for React? What are the best practices? How about firebase? Most samples are using old class methods, but I really would like to make one with Hooks. should I get data with useMemo? or another thing I can't decide; how to use a different menu for logged in and logged out users. Thank you for your clean instructions. Best.
@AndrewDevUA
@AndrewDevUA 2 жыл бұрын
awesome!
@abhilashreddy8724
@abhilashreddy8724 3 жыл бұрын
Thanks for the great video! If a parent component's state is updated will it rerender the child component or not? So, in this case, if the number is changed will it rerender the List component irrespective of useCallback?
@yahya89able
@yahya89able 2 жыл бұрын
fantastic
@alisherdotdev
@alisherdotdev 2 жыл бұрын
thanks Kyle :))
@kose241
@kose241 Жыл бұрын
you helped me get a job at coinbase, ty
@lukisIVIII
@lukisIVIII 3 жыл бұрын
You're the best teacher! You have a true gift, thank you!
@DediAnanto
@DediAnanto Жыл бұрын
Thanks, for beginner like me, I rarely use useCallback if my editor don't suggest it 😄
@exoticcoder5365
@exoticcoder5365 Жыл бұрын
Great !
@njayman
@njayman 4 жыл бұрын
Thanks
@Johnny-rn8fb
@Johnny-rn8fb 2 жыл бұрын
Thanks
@snarkykat
@snarkykat 4 жыл бұрын
Congratulations on your engagement :)
@Cloud-577
@Cloud-577 3 жыл бұрын
how do you know?
@snarkykat
@snarkykat 3 жыл бұрын
@@Cloud-577 It was on Twitter
@StephanHaewss
@StephanHaewss Жыл бұрын
From the docs "useCallback(fn, deps) is equivalent to useMemo(() => fn, deps)", so it is just a shorter way for memorizing functions as I understand it. Anyway, good video!
@naveedalirehmani4135
@naveedalirehmani4135 Жыл бұрын
So the main difference between useMemo and useCallBack is that one returns the value of the function and the other returns the actual function, but what if I use useMemo and return a function as the return value. will it work the same or am I missing something here? Like this. const functionWithMemo = useMemo(()=>function(){})
@StephanHaewss
@StephanHaewss Жыл бұрын
@@naveedalirehmani4135 As I understand it, this is equivalent to useCallback, yes.
@satindersingh9671
@satindersingh9671 3 жыл бұрын
You are the best
@ridl27
@ridl27 3 жыл бұрын
ty.
@goharamin820
@goharamin820 3 жыл бұрын
amazing
Learn Custom Hooks In 10 Minutes
9:38
Web Dev Simplified
Рет қаралды 243 М.
Learn useMemo In 10 Minutes
10:42
Web Dev Simplified
Рет қаралды 465 М.
UFC Vegas 93 : Алмабаев VS Джонсон
02:01
Setanta Sports UFC
Рет қаралды 204 М.
Каха ограбил банк
01:00
К-Media
Рет қаралды 7 МЛН
Learn useReducer In 20 Minutes
20:12
Web Dev Simplified
Рет қаралды 490 М.
How to create a responsive landing page with HTML & CSS #Shorts
0:55
Code With Bubb
Рет қаралды 221 М.
Learn useEffect In 13 Minutes
13:38
Web Dev Simplified
Рет қаралды 812 М.
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Рет қаралды 164 М.
Learn useRef in 11 Minutes
10:20
Web Dev Simplified
Рет қаралды 619 М.
Learn useContext In 13 Minutes
13:08
Web Dev Simplified
Рет қаралды 696 М.
.NET Framework vs .NET Core vs .NET vs .NET Standard vs C#
25:14
IAmTimCorey
Рет қаралды 539 М.
Junior vs Senior React Folder Structure - How To Organize React Projects
16:16
Learn useState In 15 Minutes - React Hooks Explained
15:45
Web Dev Simplified
Рет қаралды 1,1 МЛН
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 405 М.