Тёмный

The Better Way to do Loading States in React 

Josh tried coding
Подписаться 143 тыс.
Просмотров 80 тыс.
50% 1

Out of the 1001 ways of handling loading states, optimistic updates are waaay up there for me. If you use them correctly, your users will have a MUCH smoother and faster experience browsing your app (if you had any users lol)
-- my links
Discord: / discord
GitHub: github.com/joschan21

Наука

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

 

7 окт 2023

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 103   
@user-nh3uw3rv6q
@user-nh3uw3rv6q 8 месяцев назад
Love your videos and consistent work ethic Josh. Amazing content. Wishing you the best!
@KellenProctor
@KellenProctor 8 месяцев назад
Literally perfect timing! Was just dealing with this issue for a checkbox that takes waaaay to long to update. Excellent content!
@ethioapps836
@ethioapps836 8 месяцев назад
josh i really like your contents man. keep up dude. you are leveling up my skills constantly with you engaging and interesting contents . big respect dude
@clemensjanes8998
@clemensjanes8998 7 месяцев назад
Absolutely amazing video. Fast paced, but clear and understandable. Keep up the good work ❤
@mikelCold
@mikelCold 8 месяцев назад
Love it. Always great to get a real take on a the experimental API instead of people just demoing the docs.
@SaadKhan-rl4qy
@SaadKhan-rl4qy 8 месяцев назад
Man just loved your content. I don't know how you know what I was looking for.
@coffeeaddict7652
@coffeeaddict7652 8 месяцев назад
Thanks Josh, appreciate the video!
@ayushtiwari9343
@ayushtiwari9343 8 месяцев назад
This was awesome loved it ❤.
@hithakcer
@hithakcer 8 месяцев назад
Implemented Optimistic updates using React Query just last week. Pretty awesome.
@Frontend_Ed
@Frontend_Ed 8 месяцев назад
Love this 😍 how do you make the smooth code addition animations? 👀
@isipisiml4546
@isipisiml4546 8 месяцев назад
that is why im planning to use react query because of its optimistic updates. thanks josh for giving an idea on how to properly do it
@joshtriedcoding
@joshtriedcoding 8 месяцев назад
appreciate you dude
@CanRau
@CanRau 8 месяцев назад
Finally got the React Query experience thanks to RakkasJS which currently has a more simpler implementation currently but will soonish ship React Query 5 🎉 which will kinda marry RQ & tRPC 🔥
@nikitachernenko3774
@nikitachernenko3774 8 месяцев назад
Hi! nice video! Is there something special you use to show the code in vs code? or do you just go through pressing ctrl+shit+z?
@ekchills6948
@ekchills6948 8 месяцев назад
You've made my day bro
@cloynelson2974
@cloynelson2974 8 месяцев назад
Hmm, for me as a developer is a fun way to see info faster and to avoid skeletons. However, every time it happens to me as a user I feel more frustrated than in a case of a regular error. Likes case is only legit because it's insignificant enough for me to forget about an action before request gets fulfilled.
@meka4996
@meka4996 8 месяцев назад
Very useful! Thanks
@blazi_0
@blazi_0 8 месяцев назад
Another way i use sometimes, i store the data inside jotai store so ill use the react states to update it very easily from anywhere when mutating any data
@versaleyoutubevanced8647
@versaleyoutubevanced8647 8 месяцев назад
I remember I did something like that in some of my previous projects. I add in the query data cache, the new post, with "mocked" id and createdAt since they should've come from backend. Then on the onSuccess callback, I get the new post info, and change the mocked post properties with the backend ones. May not cover up all the cases, but was a valid approach back then
@Furki4_4
@Furki4_4 8 месяцев назад
Thank you, I'll give it a try on my current project. and dude, u forgot to add the typescript video at the end of the video :D
@joshtriedcoding
@joshtriedcoding 8 месяцев назад
cheers man!
@faizanahmed9304
@faizanahmed9304 8 месяцев назад
Video was helpful, but I tried with this query and Next.js (pages router) to get my inbox messages it gives a flash I don't know why. Does query does not support fully Next.js? and yes I did the same steps as you did in query (in mutation).
@antran1686
@antran1686 8 месяцев назад
is there a way to do this in server components. I use sever components to fetch the data on initial load and when a user submits a form i use revalidathPath to get the new data. is there a way to add loading state to that?
@mohitcodeswell
@mohitcodeswell 8 месяцев назад
Good one! Josh
@joshtriedcoding
@joshtriedcoding 8 месяцев назад
thanks mohit, appreciate ya man
@shreyas.sihasane
@shreyas.sihasane 8 месяцев назад
@Josh please make long projects video again like a before saas app. 😊 You are great man!
@mohammadghahri7230
@mohammadghahri7230 8 месяцев назад
it's a neat trick for making the ux better, but if there's a connection problem or user immediately close the browser it would cause a problem
@iPankBMW
@iPankBMW 8 месяцев назад
what do you use to animate the code examples?
@1weiho
@1weiho 8 месяцев назад
Actually, both PowerPoint and Apple Keynote can achieve this effect. Snappify is also a great choice!
@yanisoulhaci3369
@yanisoulhaci3369 8 месяцев назад
I love your content Josh, very unfortunate I am very bad at English I have to spend 20min on a 10min video
@shadowpony9243
@shadowpony9243 8 месяцев назад
epic!
@oliverquixchan
@oliverquixchan 8 месяцев назад
is there a particular reason you chose react query over swc?
@mustafa.wael-dev
@mustafa.wael-dev 8 месяцев назад
what is the best way to use react state Management and react query with next 13 and server component, could you share a video with the best implementation or starter?🙂
@mdmathewdc
@mdmathewdc 8 месяцев назад
How do you do the animation of the code snippets?
@BritainRitten
@BritainRitten 8 месяцев назад
Seems like a ton of work per data-fetching/mutating component. Maybe you can extract some of that behavior so it's easier to re-use across components - specifying only the things like "here's the data I want to fetch, and here's the type of mutation I'll be doing"
@gosnooky
@gosnooky 8 месяцев назад
Abstractions like that can lead to technical debt. You could write your own hooks, one per unique request to encapsulate the logic, and import them into your components, but most likely the success and error handling will be unique to each use, so you'll need to pass those functions to the hook as well as any path parameters. At that point, is it worth the bother?
@MrEnsiferum77
@MrEnsiferum77 8 месяцев назад
U can use prefetch on routes level with loaders (u need the cache function from react 18 experimental in nextjs) or with RQ query prefetch function... in v5 of RQ u can use suspense queries to eliminate unecessary rerenders
@asadmalik5075
@asadmalik5075 8 месяцев назад
Can you make a detailed tutorial on real life usage of react query along side with redux ? any advanced todo app something like that ?
@Monstermash355
@Monstermash355 8 месяцев назад
Would you always use optimistic updates instead of loaders? I mean, where is the limit if there is one? Also, is there a way to do this without react query (with server actions)? Because I feel it's the future, so react query kind of overlaps but I might be wrong
@gosnooky
@gosnooky 8 месяцев назад
With some things, a loader is fine, such as updating a profile or some other action that's expected to take time. With more real-time stuff like chats, comments and the like, optimistic updates are the way to go for UX. In fact, loading is preferable in a lot of places because lay people may think an optimistic update on something utilitarian like submitting a form means something isn't working and may try again. Loaders are a fundamental aspect of UX, but the absence of one is also - depending on the context. It's an art to be sure.
@MrEnsiferum77
@MrEnsiferum77 8 месяцев назад
RQ doing much than that... Eliminates the need for second store, or decoupling the server store data from the client side one redux/zustand... even it's client side library u can optmise the queries to kind of redux selectors so RQ observers will listen to partial cached data, and optimize refetching... in v5 u have suspense queries, which prevents some unecessary rerenders at components mount or even u can make mix with react router where u can prefetch some much needed data when some route is executed, so components are free from fetching logic and u can work with cache from RQ store... There's other good benefits from using RQ, even u can create hybrid model in SSR frontend frameworks...
@Nab_001
@Nab_001 8 месяцев назад
Josh loves React Query and we love josh we love React Query
@gregthomas5887
@gregthomas5887 8 месяцев назад
what do you use to animate the code examples? (2)
@alwaysgrowww
@alwaysgrowww 8 месяцев назад
he used keynote i guess - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE--Nm1fdreXao.html
@technical.legend
@technical.legend 8 месяцев назад
Next Video suggestion: React + vite v/s Nextjs (including deployment)
@girijeshthodupunuri1300
@girijeshthodupunuri1300 8 месяцев назад
can you link me the repo with the react query code? I really want to fully grasp the use of it!
@Mortada_DEV
@Mortada_DEV 8 месяцев назад
Please Please Pretty Please, add chapters and timestamps to your videos. This is the only thing that's missing in the great content you provide.
@fiqihalfito8776
@fiqihalfito8776 8 месяцев назад
Josh tried liking his video
@DoSmth
@DoSmth 8 месяцев назад
Can we do same things in Solid js?
@user-zx8cl1qg8u
@user-zx8cl1qg8u 8 месяцев назад
Will this work with trpc?
@irfansaeedkhan7242
@irfansaeedkhan7242 8 месяцев назад
why not use swr ? which one is better swr or react query
@stf8375
@stf8375 8 месяцев назад
you teach me something, thanks !!
@nikhil8279
@nikhil8279 8 месяцев назад
hey can u please add all your Big projects in a dedicated playlist 💗
@lovrozagar3729
@lovrozagar3729 8 месяцев назад
Great video Josh 😀. Please do a headless Shopify/Bigcommerce full project tutorial with auth, payment and deployment. Currently there is no in-depth tutorial for this anywhere on youtube. Thanks 😀
@obaid5761
@obaid5761 8 месяцев назад
You'll learn more by trying to build it yourself and figuring it out on your own :)
@eshw23
@eshw23 8 месяцев назад
@@obaid5761 lmao fr
@ejoojoo
@ejoojoo 8 месяцев назад
how to do this with trpc?
@gosnooky
@gosnooky 8 месяцев назад
I love ReactQuery.
@sujjee
@sujjee 8 месяцев назад
hey josh next long video on netflix clone?? with all new and latest nextjs 13 , tRPC and prisma
@ProductDesignTalk
@ProductDesignTalk 8 месяцев назад
I forgot to press the like button so I came back to press it 1.4K times - sub’d
@ThanHtutZaw3
@ThanHtutZaw3 7 месяцев назад
But it won't get latest like count . Every click success or error should update latest like count from DB because other user will like the post anytime .
@MVGaming77
@MVGaming77 8 месяцев назад
do i have to use 'use client' when using this?
@codinginflow
@codinginflow 8 месяцев назад
Yes, hooks can only be used inside client components
@statuschannel8572
@statuschannel8572 5 месяцев назад
only if its Next.js
@fennecbesixdouze1794
@fennecbesixdouze1794 8 месяцев назад
If your recommended way of handling one of the most common aspects of your application involves doing something like awaiting a call to cancelQueries to prevent your framework from doing what it wants to do, you know you're doing something very wrong. Couldn't think of a worse way of doing this. There are even more problems in this video: resetting the likes to the previous likes likely violates your business logic. Just because some error was returned at some point in your request doesn't mean that the likes are equal to what they were before you clicked "like". In this specific example of a like counter, someone else could be hitting "like" and it could increment for that reason. In other examples, an error might occur handling the connection but the like you submitted very well could have gone through already. Assuming that the application remains in the previous state on an error is almost never correct business logic.
@BeBoBE
@BeBoBE 8 месяцев назад
If you are going to give criticism actually read up on the docs. No he is not doing something wrong, it’s literally in the docs. Assuming an error means your mutation didn’t happen is also not as crazy as you make it seem as in most cases an error should mean that nothing has happened. Even if something did happen differently on the backend than assumed on the frontend, that problem gets handled by invalidating the data when the mutation settles.
@chi-mf1cx
@chi-mf1cx 8 месяцев назад
Bro plz make a video on when to fetch server side and client side
@user-kj2zg3pv9w
@user-kj2zg3pv9w 8 месяцев назад
I love React query but still don't understand how to use it 😢😢😢 i want to understand it's concept badly welp😢😢😢😢😢😢
@taquanminhlong
@taquanminhlong 8 месяцев назад
this already built in for Remix 😂
@eesaaphilips9271
@eesaaphilips9271 8 месяцев назад
Nice video. It seems to me like doing it yourself is just as simple as using a library (I do it myself in jQuery and Solidjs). I don't see much value in react query at all
@BandosLP
@BandosLP 8 месяцев назад
Hi Josh, can you release the source code for this?:)
@bibahbibah5108
@bibahbibah5108 8 месяцев назад
after seeing this i don't recommend optimistic method it's very tricky 😂 it make a very simple code to hell, the bests practices are based on simplicity
@MrEnsiferum77
@MrEnsiferum77 8 месяцев назад
The optmisic update, it's a bit problematic and u need to know what u are doing... In case of RQ optimistic update, react doesn't rerender, which can be problematic many times....
@tomas120
@tomas120 8 месяцев назад
nice!
@technicaltheb034
@technicaltheb034 8 месяцев назад
This video is AI generated.
@joshtriedcoding
@joshtriedcoding 8 месяцев назад
as a large language model, i cannot deny this fact
@linusbayere9206
@linusbayere9206 8 месяцев назад
@@joshtriedcoding Which tool did you use to make the video ?
@leonauswien
@leonauswien 8 месяцев назад
​@@linusbayere9206 since josh is a Chad, he uses ChadGPT
@soumyamondal
@soumyamondal 8 месяцев назад
He won't reveal
@yaswanthgosula2468
@yaswanthgosula2468 8 месяцев назад
Keynote
@bhargabdhungel9341
@bhargabdhungel9341 8 месяцев назад
ok
@stanlymark1495
@stanlymark1495 3 месяца назад
just tesing
@DanielRios549
@DanielRios549 8 месяцев назад
7:33 Be honest, this is not intuitive
@MrBlazzerBoy
@MrBlazzerBoy 8 месяцев назад
Video is way too fast.
@MathewNiania
@MathewNiania 8 месяцев назад
You should be aware they are depracating most of the "on" methods, so it might be best not to suggest them.
@joshtriedcoding
@joshtriedcoding 8 месяцев назад
Pretty sure they're only being deprecated for the query, not for the mutation
@MathewNiania
@MathewNiania 8 месяцев назад
@@joshtriedcoding Ah yes, sorry you're right! Nice vid :)
@0xtz_
@0xtz_ 8 месяцев назад
I like using swr only for this 😂 now less swr
@satyak1337
@satyak1337 8 месяцев назад
I feel like this is too complex devs and sometime frustrating for user. The only legit use cases for optimistic update is like/comment. for small use cases, simple react state is much easier/cleaner than mutate stuff.
@mknmkn2222
@mknmkn2222 8 месяцев назад
sdfsdf testing
@sburke0708
@sburke0708 8 месяцев назад
The title and the thumbnail are misleading of what this video is actually about
@AnthonyPaulT
@AnthonyPaulT 8 месяцев назад
Sorry but the third way looks terrible. I’m a staff engineer. My code is great without react query.
@rhkina
@rhkina 8 месяцев назад
Too complicated! Isn't there a simpler solution?
Далее
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Why Signals Are Better Than React Hooks
16:30
Просмотров 457 тыс.
когда повзрослела // EVA mash
00:40
Просмотров 1,3 млн
How To Load Images Like A Pro
15:48
Просмотров 358 тыс.
This Package Saved My SaaS
5:46
Просмотров 100 тыс.
10 Tailwind Tricks You NEED To Know!
10:45
Просмотров 272 тыс.
Loading Your React Data Like This is Awesome
13:27
Просмотров 101 тыс.
7 Awesome TypeScript Types You Should Know
8:57
Просмотров 77 тыс.
Avoid using `isLoading` for Data Fetching in React
12:35
Every React Concept Explained in 12 Minutes
11:53
Просмотров 420 тыс.
iPhone 16 - КРУТЕЙШИЕ ИННОВАЦИИ
4:50