Тёмный

React 18 useTransition Hook Crash Course 

Web Dev Simplified
Подписаться 1,6 млн
Просмотров 147 тыс.
50% 1

FREE React Hooks Course: courses.webdevsimplified.com/...
React 18 recently had its official non-beta release and with it came multiple new React hooks. Of those hooks, the one I am most excited for is the useTransition hook. This hook helps increase the performance of your applications, increase the responsiveness of your application to users, and overall just make your application better. This video is all about how this new hook works.
📚 Materials/References:
FREE React Hooks Course: courses.webdevsimplified.com/...
useTransiton Article: blog.webdevsimplified.com/202...
🌎 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
⏱️ Timestamps:
00:00 - Introduction
00:30 - Why you need useTransition
01:53 - How useTransition works
03:00 - How to implement useTransition
06:35 - When to use useTransition
#useTransition #WDS #React

Опубликовано:

 

28 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 189   
@marindedic441
@marindedic441 2 года назад
React really needs to start naming their hooks better
@ChrisAthanas
@ChrisAthanas 2 года назад
Yes I was thinking it should be called useLowPriority or useDeferredPriority or useInterruptable
@adityaanuragi6916
@adityaanuragi6916 Год назад
Ikr even the startTransition doesn't make a lot of sense to me. I would've preferred a name like lowPriority or something
@Toulkun
@Toulkun Год назад
I thought transitions were about those ordinary transitions with ease, ease out, ease in out 😂
@dreamyrhodes
@dreamyrhodes Год назад
This! Although refactoring might break a lot now. But it is really bad especially for beginners but also for developers that don't develop React all the time but come back to it for a new need once in a while.
@royhyde8842
@royhyde8842 10 месяцев назад
Tell me about it. You could never tell by the hook's name that that is what it does.
@timj7785
@timj7785 Год назад
this feels like a good use case for debounce as well, thanks for sharing, you made it super clear!
@tomino133
@tomino133 2 года назад
You're an absolute legend. Thanks for a nice and clear explanation.
@SushilKumar-ig8ls
@SushilKumar-ig8ls 2 года назад
Totally Loved it. Thank you for such new concepts
@zhesun4853
@zhesun4853 2 года назад
really love this guy, get knowledge explained so clear! thumbs up!👍
@VondiaLC
@VondiaLC 2 года назад
Love your content! Thanks man keep up the good work
@95jugal
@95jugal 2 года назад
Love your content ❣️. Please make more videos on other features of React 18 too.
@fiqriardiansyah876
@fiqriardiansyah876 2 года назад
so basically it's like web workers who working at background thread
@kantyDarius
@kantyDarius 2 года назад
This hooks is so helpful.. Thanks Kyle... Cheers from Argentina.
@maranaivoson3199
@maranaivoson3199 2 года назад
Very clear, thank you Kyle👍
@erezrosenbloom330
@erezrosenbloom330 2 года назад
This was an excellent overview. Thanks!
@Yadiel458x
@Yadiel458x Месяц назад
It just clicked! Very good explanation!
@EvertJunior
@EvertJunior 2 года назад
Thanks Kyle, very informative ! Really good hook
@DiariesByMin
@DiariesByMin 2 года назад
Absolutely simple and clear THANKS
@bonkshiba1916
@bonkshiba1916 Год назад
Nice and clear explanation, thanks.
@iivnnal7483
@iivnnal7483 2 года назад
CONGRATULATIONS! 🎉
@anatolydyatlov963
@anatolydyatlov963 Год назад
Nice! I didn't know about this one.
@tech3425
@tech3425 Год назад
Had a tough time wrapping my head around this hook. Your video really simplified it a LOT. The key takeaway was that all `set` events are high priority by default, and the `useTransition` marks something as low priority instead.
@Kennomie
@Kennomie Год назад
Really nice explanation, thank you!
@dlysele
@dlysele Год назад
Very easy to understand. Thank you.
@tornikenijaradze6422
@tornikenijaradze6422 Год назад
Thanks for the video!
@romanjs4909
@romanjs4909 Год назад
amazing explanation! Subscribed
@lakshyapandit6624
@lakshyapandit6624 2 года назад
This hook is a life changer. Thanks bro..
@leah9227
@leah9227 2 года назад
This is kind of an async function with a isPending loading flag. Awesome, thanks for the information!
@manishpanchal1098
@manishpanchal1098 10 месяцев назад
Thanks for a nice and clear explanation.
@pcr3323
@pcr3323 2 года назад
Sir, I don't know whether you'll read My comments, But THANKS ALOTTTT ❤️. I Got My developer job mostly because of your tutorials. And I'm so grateful for this sir. God bless you. I wish I could meet you in real and thank you ❤️... Really thank you for making web development simple 🥰 ... I'm a commerce graduate and taught myself coding .. and mostly your tutorials is where I refer to .. and the project I did to land my job wouldn't have been possible without your help.. Again THANKS ALOT ❤️🙏
@TusharJade101
@TusharJade101 2 года назад
Your video are very easy to understand man lot of love from India ❤️
@DEV_XO
@DEV_XO 2 года назад
Amazing mate, thanks!
@electricindro2236
@electricindro2236 2 года назад
Thanks! Nice explanation 🔥
@rvft
@rvft 2 года назад
I literally opened RU-vid to see if WDS posted a video and he did lol
@bayasahamed1815
@bayasahamed1815 11 месяцев назад
Thanks for the clear explanation!! :-)
@ADITYA-qr6il
@ADITYA-qr6il 2 года назад
You explain a useTraction in a very simple way 🤯
@codesymphony
@codesymphony Год назад
my favourite hook useTraction
@Linuslkm
@Linuslkm Год назад
@@codesymphony your comment made me laugh thanks lol
@_KITISH
@_KITISH Год назад
@@Linuslkm lol yeah 😂
@gravisrinivas
@gravisrinivas Год назад
You are the best react tutor on youtube
@ayaalnahas3577
@ayaalnahas3577 Год назад
Great tutorial !! THANKS!
@moaazbhnas886
@moaazbhnas886 Год назад
Awesome explanation!
@lindawang3008
@lindawang3008 Год назад
Thank you for making this amazing video! Easy to follow! Get the idea about "useTransansition" in just 7 mins! 😀
@23LS023
@23LS023 Год назад
Your channel is the best, never met a person, who can explain any difficult topic so easily, that even a non-English speakers can understand every single detail. Thank you very much ...
@omarbailal5751
@omarbailal5751 2 года назад
Great content, thank you sir.
@LePhenixGD
@LePhenixGD Год назад
Damn, didn't even know you could use this in React! That's amazing!
@yazraf
@yazraf 2 года назад
Dude you are awesome!
@danish_ayoub
@danish_ayoub 2 года назад
Very useful and well explained
@ControlAllDa1337
@ControlAllDa1337 2 года назад
Thanks my guy, this looks like it could be useful for me atm, I need to filter through a list of categories as the user types. The list is small atm but could potentially become very large
@nicklane4868
@nicklane4868 Год назад
Amazing video, thanks.
@code-for-mars
@code-for-mars Год назад
Best explanation !!
@yfzhangphonn
@yfzhangphonn 11 месяцев назад
Cure for INP, nice hook and thanks for sharing.
@AadeshKulkarni
@AadeshKulkarni 2 года назад
Beautiful!
@bidishadas832
@bidishadas832 2 года назад
Awesome explanation.
@ShaharHarshuv
@ShaharHarshuv Год назад
What's amazing is that the delay is CPU related, it's synchronous. But when you do that you still manage to update the UI to "loading" before the thread is stuck very easily. Amazing
@elijahandrew6790
@elijahandrew6790 Год назад
The best programming tutor out there. I'm very careful with words I use to describe people (words like "best", "most awesome" etc), and I rarely ever use them. But...Damn! Kyle, You're the BEST. Thanks for helping me become a much better programmer. Lots of love from Nigeria
@slowbr600rr
@slowbr600rr 2 года назад
Congratulations 😉
@MohamadOmar-oi3ur
@MohamadOmar-oi3ur Год назад
YOU MAN are a life saver !!! I really enjoy watching your videos even i already have background about what you are talking about , but at the same time you guided me and gave me a lot of solution about some old and new problems ! I appreciate it Bro
@dawid_dahl
@dawid_dahl 2 года назад
Thank you!
@amershboul9107
@amershboul9107 Год назад
Very Useful
@kranthikumar5215
@kranthikumar5215 Год назад
Love u man❤
@wasimnadaf11
@wasimnadaf11 2 года назад
Great video
@orkhanrustamli2039
@orkhanrustamli2039 2 года назад
Hey, great content as always!!! Could you please make a video about Kafka usage with NodeJS. I am really interested on some advanced topics such as manual commit, exact once delivery, concurrency and etc!
@shinodinhaa
@shinodinhaa 2 года назад
cool, will let me stop adding lodash to my projects only to use their debounce function hahaha
@mahdikamran8061
@mahdikamran8061 10 месяцев назад
Thank you.
@wellingtonostemberg7585
@wellingtonostemberg7585 2 года назад
Nice content
@samiurias
@samiurias 17 дней назад
Thanks!
@zohayrslileh2734
@zohayrslileh2734 2 года назад
thank you very much
@Shizzymynizzy
@Shizzymynizzy 2 года назад
Very nice
@wodyd318
@wodyd318 2 года назад
thank you
@bonnes04
@bonnes04 Год назад
Ni noma... respect
@dilanbesong1877
@dilanbesong1877 2 года назад
Thank you Kyle for helping me grow in development, please can you make a video on how to automatically delete documents in mongodb
@yigitruzgaruzun7289
@yigitruzgaruzun7289 2 года назад
Thanks.
@ismailelsayed936
@ismailelsayed936 2 года назад
thx kyle
@NicoKupfer
@NicoKupfer Год назад
One small note, the startTransition method also causes a render because it has to change the status to isPending=true. so in the end it’s 3 renders vs 1.
@dreamyrhodes
@dreamyrhodes Год назад
But only if you use isPending in your JSX, not?
@bigti1199
@bigti1199 Год назад
It changes the state of pending but it still does so in the same render it changes the state of the array So it does all that in 1 render
@NicoKupfer
@NicoKupfer Год назад
@@bigti1199 6:50 - startTransition runs asynchronously (i'm talking about updating the state). It doesn't matter in terms of performance because of the amount of resources that useTransition saves makes it all worthwhile. But it does render three times. Here's why: Without startTransition, it will do *synchronously* (although your computer will be really suffering for 3 seconds) one update (setInput() and setList()). With startTransition, it does it three times: - setInput - (setTransition gets delayed) -> sets `isPending` to true. - (setTransition code runs) -> setList - setTransition Ends, and when it ends (because it doesn't know what happens inside of it) sets `isPending` to false. Since this is an asynchronous operation, it cannot change `isPending` to false on the same rerender as `setList(l)`. The last point, which is the one i was referring to, is due to a state being updated inside of startTransition. This is something that Facebook knows, and they have a warning in case they detect multiple re-renders while running the code. "'Otherwise concurrent mode guarantees are off the table.'" Feel free to check the ReactStartTransition.js file of the source code :)
@Gitaadiguna
@Gitaadiguna 2 года назад
Lol this is the exact answer my app's issue looking for
@wisdomcube7789
@wisdomcube7789 2 года назад
thanks
@morgandorferr
@morgandorferr 2 года назад
Kyle is great 👍🏻
@Victor_Marius
@Victor_Marius 2 года назад
Super condensed: setList(Array(LIST_SIZE).fill(e.target.value)
@firewatermoonsun
@firewatermoonsun Год назад
useDeferredValue() also sets to lower priority.
@mealcode
@mealcode 2 года назад
before useTransition, i used debounce to make similar functionality working.
@SyamKishoreNaidu
@SyamKishoreNaidu 2 года назад
Thanks
@WebDevSimplified
@WebDevSimplified 2 года назад
Thank you so much for the support!
@arnoderoost3479
@arnoderoost3479 Год назад
Thank you for the insights. Any ideas on how to use this in Next js?
@essaadi_elmehdi6784
@essaadi_elmehdi6784 2 года назад
But the loop will execute inside handleChange. So the useTranslition will help us just on render the list after input have been rendered (so rendering the input will be more fast because thet list wont render with it)
@irlshrek
@irlshrek 2 года назад
Man.. This makes me appreciate Svelte so much
@danieltkach2330
@danieltkach2330 2 года назад
How is this handled in Svelte?
@kevinc4736
@kevinc4736 2 года назад
^
@krishgarg2806
@krishgarg2806 2 года назад
I mean I did this in svelte and it was sluggish so what are you talking about? let val = ""; let list = []; const LIST_SIZE = 20000; const updateList = (val) => { list = [] for (let i = 0; i < LIST_SIZE; i++) { list = [...list, val] } } $: updateList(val) {#each list as item, idx (idx)} {item} {/each}
@krishgarg2806
@krishgarg2806 2 года назад
Update: Added debouncing and works much better: let val = ""; let list = []; const LIST_SIZE = 20000; const debounce = (func, time = 1000) => { let timeoutId = null; return (...args) => { if (timeoutId) { console.log(`Cleared timeout with id: ${timeoutId}`) clearTimeout(timeoutId); } timeoutId = setTimeout(() => { console.log(`Called timeout callback with id: ${timeoutId}`) func(...args) }, time) } } const updateList = debounce((val) => { list = [] if (!val) return; for (let i = 0; i < LIST_SIZE; i++) { list = [...list, val] } }); $: updateList(val) {#each list as item, idx (idx)} {item} {/each}
@mdridoy-ef2pw
@mdridoy-ef2pw 2 года назад
when someone types 5 letters, the startTransition code block also fires 5 times. It would be nice if they added option to only fire the startTransition code block for the last input. just like how a debounce function works.
@Vesunchik123456789
@Vesunchik123456789 2 года назад
usedeferredvalue is also a new hook which can solve that problem
@334Bena
@334Bena 2 года назад
You could probably set it back with a useEffect hook using a setTimeout that waits for the user to stop typing in order to actually set the new state
@allone258
@allone258 2 года назад
better use timeout, with 0.5 sec after input. if user types again before 0.5sec, reset the timeout.
@FilipCodes
@FilipCodes 2 года назад
Thats all nice and fun until state changes do not depend on each other
@niranjanpatil7878
@niranjanpatil7878 2 года назад
informative
@VaibhavShewale
@VaibhavShewale 2 года назад
just use another useState and make it a priority! i like it
@romy4romy4
@romy4romy4 Год назад
This always being called threshold thru ages.
@user-es2vr3cv1v
@user-es2vr3cv1v 2 года назад
Can you review all of the hooks and react18 updates?
@krishangopal2475
@krishangopal2475 2 года назад
React 18 updates are useTransition hook that you already saw which is a concurrent mode feature that React team has been working on for years. And another update is useId hook that you can generally use to generate unique ids in your application
@Kingofmylife007
@Kingofmylife007 2 года назад
that's great usefull. where is useId and another hooks.
@abdelheqbourouni3677
@abdelheqbourouni3677 2 года назад
In your example we can use flushSync !!
@usd00
@usd00 2 года назад
Great. btw why don't you join the copilot waitlist?
@TroenderTass
@TroenderTass 2 года назад
Sound to me the concept is explained wrong. The rendering merging might be correct, but the only reason why this blocks, is that non of the async state change calls will execute until the current function exit. That is the normal eventloop in js. All asynchronous functions will be put in a que that will exectue when the stack is cleared. So the setTransition is just another async function that wont block, but alow the handler function to exit.
@tangkenangenamotv6401
@tangkenangenamotv6401 Год назад
Good video as always, man! Thank you!!! But what's the difference between useTransition and useDebounce?
@zai8440
@zai8440 Год назад
same question, since both of these will be used on maybe the same use cases
@ygormartinsr
@ygormartinsr 2 года назад
Lesgooo
@rudestewing
@rudestewing 2 года назад
this is a hook I'm looking for
@amansaxena4446
@amansaxena4446 Год назад
somewhat its similar to debounce implementation for startTransitoin hook
@eileen0307
@eileen0307 2 года назад
could you record a video to talk about nextjs?
@kvirajs
@kvirajs 2 года назад
.... so ig we can think of it as moving those to task queue and executing later
@krishangopal2475
@krishangopal2475 2 года назад
Lets say input changes by 1 character and code is called inside startTransition which is still being calculated in the background. When u type some more characters which call that handleChange everytime u type a character, Does that code inside startTransition gets cancelled whenever it runs setInput again as handleChange have been called multiple times?
@michaelkurzewski2937
@michaelkurzewski2937 2 года назад
I think it's fairly easy to check. Console log max index of each iteration. If the index same for each iteration (equal to items count) then it's not cancelled.
@awekeningbro1207
@awekeningbro1207 2 года назад
That's the debounce functionality. You have to do implement that yourself.
@Mauro0
@Mauro0 2 года назад
Yes, it does run every time. If you have, let's say, a search input and want to avoid making a request for every character, then you should implement a Debounce().
@Grim_tidings
@Grim_tidings 2 года назад
Yes. However, if you’re using lodash, there’s a useDebounce hook included that can alleviate this issue. If not, implementing it isn’t hard: function useDebounce(value, delay) { const [debouncedValue, setDebouncedValue] = useState(value); useEffect( () => { const handler = setTimeout(() => { setDebouncedValue(value); }, delay); return () => { clearTimeout(handler); }; }, [value, delay] ); return debouncedValue; };
@roshanlalsahu7846
@roshanlalsahu7846 2 года назад
what is the execution order in case of async function?
@Kim-by5uy
@Kim-by5uy Год назад
i feel isPending should've been the second value. Because you wont always need it, which will cause an 'unused variable' error with typescript
@mahmoudzakria6946
@mahmoudzakria6946 8 дней назад
Man, I thought it was for making CSS transitions like fade-in/out a Modal component or something 😅
@Aurelia22dr
@Aurelia22dr 2 года назад
Really cool and useful react hook, now I may make the variable from the piece of my brain that determines which gender im identifying more at the moment and put it into the array of depenencies as a second argument of useEffect hook and easily and painlesly transition myself to the opposite gender
@ThanHtutZaw3
@ThanHtutZaw3 Год назад
this better than react docs
Далее
React 18 useDeferredValue Hook Crash Course
7:52
Просмотров 68 тыс.
useTransition() vs useDeferredValue | React 18
16:22
Просмотров 94 тыс.
He turned a baseball into a stylish shoe😱
00:59
Просмотров 399 тыс.
Задержали в аэропорту
00:56
Просмотров 656 тыс.
Why Signals Are Better Than React Hooks
16:30
Просмотров 457 тыс.
Top 6 React Hook Mistakes Beginners Make
21:18
Просмотров 561 тыс.
Learn React Hooks: useTransition - Simply Explained!
10:41
How To Maximize Performance In Your React Apps
12:58
Просмотров 93 тыс.
This One Line Of Code Catches React Bugs For You
15:55
Learn TypeScript Generics In 13 Minutes
12:52
Просмотров 228 тыс.
Most Beginner React Developers Do This Wrong
13:47
Просмотров 225 тыс.