The Better Way to do Loading States in React

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 108

  • @oldqwfdqwqwfq
    @oldqwfdqwqwfq ปีที่แล้ว +20

    Love your videos and consistent work ethic Josh.
    Amazing content. Wishing you the best!

  • @KellenProctor
    @KellenProctor ปีที่แล้ว +2

    Literally perfect timing! Was just dealing with this issue for a checkbox that takes waaaay to long to update. Excellent content!

  • @mikelCold
    @mikelCold ปีที่แล้ว +3

    Love it. Always great to get a real take on a the experimental API instead of people just demoing the docs.

  • @cloynelson2974
    @cloynelson2974 ปีที่แล้ว +19

    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.

  • @ethioapps836
    @ethioapps836 ปีที่แล้ว +1

    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

  • @isipisi4546
    @isipisi4546 ปีที่แล้ว +13

    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  ปีที่แล้ว +3

      appreciate you dude

    • @CanRau
      @CanRau ปีที่แล้ว +3

      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 🔥

  • @clemensjanes8998
    @clemensjanes8998 ปีที่แล้ว

    Absolutely amazing video. Fast paced, but clear and understandable. Keep up the good work ❤

  • @SaadKhan-rl4qy
    @SaadKhan-rl4qy ปีที่แล้ว

    Man just loved your content. I don't know how you know what I was looking for.

  • @hithakcer
    @hithakcer ปีที่แล้ว

    Implemented Optimistic updates using React Query just last week. Pretty awesome.

  • @iPankBMW
    @iPankBMW ปีที่แล้ว +6

    what do you use to animate the code examples?

    • @1weiho
      @1weiho ปีที่แล้ว

      Actually, both PowerPoint and Apple Keynote can achieve this effect. Snappify is also a great choice!

  • @BritainRitten
    @BritainRitten ปีที่แล้ว +12

    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 ปีที่แล้ว +2

      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 ปีที่แล้ว

      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

  • @Furki4_4
    @Furki4_4 ปีที่แล้ว +1

    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

  • @nikitachernenko3774
    @nikitachernenko3774 ปีที่แล้ว +1

    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?

  • @faizanahmed9304
    @faizanahmed9304 ปีที่แล้ว +1

    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).

  • @coffeeaddict7652
    @coffeeaddict7652 ปีที่แล้ว

    Thanks Josh, appreciate the video!

  • @antran1686
    @antran1686 ปีที่แล้ว +1

    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?

  • @Frontend_Ed
    @Frontend_Ed ปีที่แล้ว +1

    Love this 😍 how do you make the smooth code addition animations? 👀

  • @versaleyoutubevanced8647
    @versaleyoutubevanced8647 ปีที่แล้ว +2

    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

  • @Nab_001
    @Nab_001 ปีที่แล้ว +1

    Josh loves React Query and we love josh we love React Query

  • @mohammadghahri7230
    @mohammadghahri7230 ปีที่แล้ว

    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

  • @Monstermash355
    @Monstermash355 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว

      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...

  • @ayushtiwari9343
    @ayushtiwari9343 ปีที่แล้ว

    This was awesome loved it ❤.

  • @mdmathewdc
    @mdmathewdc ปีที่แล้ว +1

    How do you do the animation of the code snippets?

  • @blazi_0
    @blazi_0 ปีที่แล้ว

    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

  • @meka4996
    @meka4996 ปีที่แล้ว

    Very useful! Thanks

  • @ekchills6948
    @ekchills6948 ปีที่แล้ว

    You've made my day bro

  • @shreyas.sihasane
    @shreyas.sihasane ปีที่แล้ว +3

    @Josh please make long projects video again like a before saas app. 😊
    You are great man!

  • @mohitcodeswell
    @mohitcodeswell ปีที่แล้ว +1

    Good one! Josh

  • @mustafa.wael-dev
    @mustafa.wael-dev ปีที่แล้ว

    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?🙂

  • @yanisoulhaci3369
    @yanisoulhaci3369 ปีที่แล้ว

    I love your content Josh, very unfortunate I am very bad at English I have to spend 20min on a 10min video

  • @gregthomas5887
    @gregthomas5887 ปีที่แล้ว

    what do you use to animate the code examples? (2)

    • @alwaysgrowww
      @alwaysgrowww ปีที่แล้ว

      he used keynote i guess - th-cam.com/video/-Nm1fdreXao/w-d-xo.html

  • @Mortada_DEV
    @Mortada_DEV ปีที่แล้ว +1

    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.

  • @tallawahh
    @tallawahh 2 หลายเดือนก่อน

    Yeah i'd probably just do a timeout or error toast in the past.....slowly becoming a senior dev

  • @oliverquixchan
    @oliverquixchan ปีที่แล้ว

    is there a particular reason you chose react query over swc?

  • @DanielRios549
    @DanielRios549 ปีที่แล้ว +1

    7:33 Be honest, this is not intuitive

  • @girijeshthodupunuri1300
    @girijeshthodupunuri1300 ปีที่แล้ว

    can you link me the repo with the react query code? I really want to fully grasp the use of it!

  • @asadmalik5075
    @asadmalik5075 ปีที่แล้ว

    Can you make a detailed tutorial on real life usage of react query along side with redux ? any advanced todo app something like that ?

  • @technical.legend
    @technical.legend ปีที่แล้ว +1

    Next Video suggestion: React + vite v/s Nextjs (including deployment)

  • @ThanHtutZaw3
    @ThanHtutZaw3 ปีที่แล้ว

    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 .

  • @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 ปีที่แล้ว

      @@obaid5761 lmao fr

  • @AleksandrNeo
    @AleksandrNeo ปีที่แล้ว

    Can we do same things in Solid js?

  • @MVGaming77
    @MVGaming77 ปีที่แล้ว +1

    do i have to use 'use client' when using this?

    • @codinginflow
      @codinginflow ปีที่แล้ว

      Yes, hooks can only be used inside client components

    • @statuschannel8572
      @statuschannel8572 10 หลายเดือนก่อน

      only if its Next.js

  • @irfansaeedkhan7242
    @irfansaeedkhan7242 ปีที่แล้ว

    why not use swr ? which one is better swr or react query

  • @fiqihalfito8776
    @fiqihalfito8776 ปีที่แล้ว

    Josh tried liking his video

  • @AndrewSemyonov-n3p
    @AndrewSemyonov-n3p ปีที่แล้ว

    Will this work with trpc?

  • @SIGTERM-f1n
    @SIGTERM-f1n ปีที่แล้ว

    I love React query but still don't understand how to use it 😢😢😢 i want to understand it's concept badly welp😢😢😢😢😢😢

  • @gosnooky
    @gosnooky ปีที่แล้ว

    I love ReactQuery.

  • @ejoojoo
    @ejoojoo ปีที่แล้ว

    how to do this with trpc?

  • @rajsandhu3344
    @rajsandhu3344 4 หลายเดือนก่อน

    You guys can follow along 😮

  • @nikhil8279
    @nikhil8279 ปีที่แล้ว

    hey can u please add all your Big projects in a dedicated playlist 💗

  • @MrEnsiferum77
    @MrEnsiferum77 ปีที่แล้ว

    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....

  • @sujjee
    @sujjee ปีที่แล้ว

    hey josh next long video on netflix clone?? with all new and latest nextjs 13 , tRPC and prisma

  • @fennecbesixdouze1794
    @fennecbesixdouze1794 ปีที่แล้ว +5

    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 ปีที่แล้ว +2

      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.

  • @LlamaPony
    @LlamaPony ปีที่แล้ว

    epic!

  • @BandosLP
    @BandosLP ปีที่แล้ว

    Hi Josh, can you release the source code for this?:)

  • @taquanminhlong
    @taquanminhlong ปีที่แล้ว

    this already built in for Remix 😂

  • @chi-mf1cx
    @chi-mf1cx ปีที่แล้ว

    Bro plz make a video on when to fetch server side and client side

  • @stf8375
    @stf8375 ปีที่แล้ว

    you teach me something, thanks !!

  • @fulldeploy
    @fulldeploy ปีที่แล้ว

    I forgot to press the like button so I came back to press it 1.4K times - sub’d

  • @bibahbibah5108
    @bibahbibah5108 ปีที่แล้ว +1

    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

  • @eesaaphilips9271
    @eesaaphilips9271 ปีที่แล้ว +1

    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

  • @technicaltheb034
    @technicaltheb034 ปีที่แล้ว +61

    This video is AI generated.

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +103

      as a large language model, i cannot deny this fact

    • @linusbayere9206
      @linusbayere9206 ปีที่แล้ว +2

      @@joshtriedcoding Which tool did you use to make the video ?

    • @leonauswien
      @leonauswien ปีที่แล้ว

      ​@@linusbayere9206 since josh is a Chad, he uses ChadGPT

    • @soumyamondal
      @soumyamondal ปีที่แล้ว

      He won't reveal

    • @yaswanthg5
      @yaswanthg5 ปีที่แล้ว

      Keynote

  • @AnthonyPaulT
    @AnthonyPaulT ปีที่แล้ว +3

    Sorry but the third way looks terrible. I’m a staff engineer. My code is great without react query.

  • @MrBlazzerBoy
    @MrBlazzerBoy ปีที่แล้ว +3

    Video is way too fast.

  • @stanlymark1495
    @stanlymark1495 8 หลายเดือนก่อน

    just tesing

  • @bhargabdhungel9341
    @bhargabdhungel9341 ปีที่แล้ว

    ok

  • @satyak1337
    @satyak1337 ปีที่แล้ว

    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.

  • @rhkina
    @rhkina ปีที่แล้ว

    Too complicated! Isn't there a simpler solution?

  • @MathewNiania
    @MathewNiania ปีที่แล้ว

    You should be aware they are depracating most of the "on" methods, so it might be best not to suggest them.

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +2

      Pretty sure they're only being deprecated for the query, not for the mutation

    • @MathewNiania
      @MathewNiania ปีที่แล้ว

      @@joshtriedcoding Ah yes, sorry you're right! Nice vid :)

  • @0xtz_
    @0xtz_ ปีที่แล้ว

    I like using swr only for this 😂 now less swr

  • @mknmkn2222
    @mknmkn2222 ปีที่แล้ว

    sdfsdf testing

  • @tomas120
    @tomas120 ปีที่แล้ว

    nice!

  • @sburke0708
    @sburke0708 ปีที่แล้ว

    The title and the thumbnail are misleading of what this video is actually about

  • @quocthangpham6465
    @quocthangpham6465 4 หลายเดือนก่อน

    Bad video