Loading States are Killing Your User Experience

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ค. 2023
  • They are, man. But there's a way to handle them so gracefully. Let's look at which loading state pattern to avoid like the plague and THEN how to actually improve your UX with awesome loading states!
    -- my links
    My GitHub: github.com/joschan21
    Discord: / discord
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    NOOO I accidentally deleted the top comment trying to remove a spambot 😭😭 sorry to the person who wrote that, it was so kind too.

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

    ngl I was literally trying to make this work on my project! Thanks man!

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

    I just found the channel few days back, and now I am addicted....❤❤❤❤

  • @ivangemota1527
    @ivangemota1527 ปีที่แล้ว +4

    now I understand the suspense well, thanks josh 👊

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

      It’s a pretty simple concept really with such a big payoff. Cheers dude!

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

    🔥🔥🔥 man youtube was lacking u , hope u keep up the amazing vids and good luck on your way

  • @jeremyjacob6646
    @jeremyjacob6646 ปีที่แล้ว +16

    When taking this approach, be very aware of layout shift. If the placeholder is not the same size as the final content it can lead to an even worse experience than loading everything server-side.

    • @jeankaelaugustin641
      @jeankaelaugustin641 11 หลายเดือนก่อน

      Thanks

    • @botan1996
      @botan1996 9 หลายเดือนก่อน

      You can place a ghost skeleton with css in the size of the actual content that is waited for and being loaded. Not really an issue, am I missing anything?

    • @joshuasingh854
      @joshuasingh854 3 หลายเดือนก่อน

      @@botan1996 But how do you know the height of the content? And if it changes you'll have to keep changing the height then...

  •  ปีที่แล้ว

    Wow!! You really keep things simple man!! [... AWESOME]; Thank you very much!!

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

    Super helpful - many thanks!

  • @abhiramsatpute
    @abhiramsatpute ปีที่แล้ว +7

    Great introduction to Lazy Loading, here's what I think would be the next steps for intermediate to advanced Loading State handling:
    1 ) Lazy Loading
    2 ) React Query
    3 ) Replicache-like product integration

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

      I am curios about is there any place for react query in server components

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

      @@heyjitendra I haven't tested this case, but i think that since one of react query's key feature is cache handling, it would be better to keep that part of data on the client for easy handling of cache invalidation

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

      2) is awesome for handling client-loading behaviour. I feel like 1) is more about performance than it is about handling loading, but your points are great if you wanna get into making the UX even better

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

      @@heyjitendra With some finagling you can fill up react query cache on the server and stream that to the client. I'm not sure how/if it works with app dir (yet, I'm sure when app is fully released and stable Tanner+team will think of something), but when using pages and getServerSideProps you can definitely do it. tRPC has this built in.
      Granted that's not a server component but getServerSideProps, but again, when appDir is stable there will probably be some function you can call to prefetch query cache and stream that, so you'd get the benefits of both suspense/server components/ssr, and client side react query for refetching and mutations and all that.
      TL;DR works great with /pages and getServerSideProps in nextjs, /app and server components will likely come soon

  • @tube-rp1nb
    @tube-rp1nb ปีที่แล้ว

    you are right.the first sucks. your solution is nice.thank you it was really helpful .i am taking your next courses .

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

    Awesome as always

  • @rahimco-su3sc
    @rahimco-su3sc ปีที่แล้ว +2

    hi ! is it necessary to not use material UI with next js inorder to take advantage of next js server components ? || because material UI needs to use a lot's of context providers such as the theme provider !!

  • @GabrielMartinez-ez9ue
    @GabrielMartinez-ez9ue ปีที่แล้ว

    So i would basically have to recreate a Image component which can be wrapped with a suspense right? what about handle it with state with onLoadingComplete to show a skelleton while waiting? It works with one image, but rendering an array of images is not working right for me as I am testing it right now.

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

    +1 for the non-clickbait (and the content). Thank you

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

    Should we use the axios and react query in nextjs app directory OR native fetch?

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

    Hi! I actually implemented something similar on my next app with Suspense and it works perfectly when I reload the page. However, whenever I navigate to the page from some other page, it still waits for all the data to fetch before showing me any content 😢.

  • @XxbankerboomxX
    @XxbankerboomxX ปีที่แล้ว +8

    Instead of a text saying Loading... you could also use a component for example" "and in the Loader component have for example a loading animation from Chakra UI

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

      yessir. Personally prefer skeletons over loading spinners but I guess it's preference

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

      @@joshtriedcoding i havent thought of using skeleton, good idea :)

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

    I knew about the Suspense and Lazy loading
    in react but i would never know i could use it this way

  • @sincethatmoment
    @sincethatmoment ปีที่แล้ว +15

    Data streaming is so badass. I feel like we're experiencing prime of web development

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

      It really is. The current direction of web dev and react certainly is not without criticism (especially regarding server components) but the general tendency is awesome

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

    Super cool. thanks :)!

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

    You're amazing man

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

    Great vid man thanks for sharing that knowledge. Those thumbs kinda sucks though 😅

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

    This channel is REALLY underrated

  • @omarkarim9298
    @omarkarim9298 ปีที่แล้ว +4

    Lol the way he was going on about thought it would be something more interesting than suspense 😂

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

      Don’t you dare call suspense boring 🤨📸

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

    didnt know about the react suspense component :b I do remember that the images has a lazy loading property as default as well (recommendation.tsx when returning an image)

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

    At 04:05 I would highly recommend you write "export default Recommendation as unknown as (props: Props) => JSX.Element" instead of ignoring the typescript error.
    Otherwise you also wont see any typescript errors if you pass invalid props to that component.

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

      Latest Typescript beta supports async TSX Components 😊

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

    Dope content!

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

    Can you please teach about parallel routes and intercepting routes in the nextjs... I can't understand how it works

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

    Forgive me if this is a stupid question; but what if you're working with a solution like hitting a rest API or using an ORM to get data where you might not know individual keys ahead of time (getting all posts from a database or getting all github repos from the github rest api) and you fetch all of your data at once anyway?

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

    Thank You.

  • @GTX-cr4ob
    @GTX-cr4ob ปีที่แล้ว

    hey josh can you make video on authentication I next 13.4 with custom credentials provider and also how to make layout for admin routes and login route

  • @fabiojonathanarifin1
    @fabiojonathanarifin1 5 หลายเดือนก่อน

    amzing

  • @MDKhan-ww5tp
    @MDKhan-ww5tp ปีที่แล้ว +14

    Hey you should make a video on parallel routes and intercepting routes

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

      Is there any use case you’d think fits well into a video?

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

      Have /login rendered in a modal if the link has been clicked manually

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

      @@joshtriedcoding Also an instagram-like post modal that's its own page when refreshed/linked directly

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

      @@CanRau ah that is actually a cool use-case, cheers man

    • @MDKhan-ww5tp
      @MDKhan-ww5tp ปีที่แล้ว +3

      @@joshtriedcoding @Cau Rau Gave A Good Idea

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

    banger

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

    Can't we use Parallel route here? It's recommended in the docs too.

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

    Awesome

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

    loading states are killing your user experience so let's implement loading states XD

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

    Do you think React-Query still nessesary when NextJS is such powerful like this? NextJS + ReactQuery to me is a little bit overkilled. What is your opinions?

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

      In my opinion absolutely not. React query is AWESOME in Next for any client-side data fetching. Love it. Goes super well together. I'd recommend giving it a shot, I think you might just like it too!

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

      I’d still use React Query to fetch data from client events like on click or on submit for example. That being said, I think it’s difficult to find use cases for useQuery in Next JS

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

    I wonder what benefits this has over client-side loading? I guess the benefit is that its a server component and thus less JavaScript is needed on the client. Anything else?

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

      The whole thing about server components and their loading state was unclear to me for a pretty long time. The loading.tsx is just on a per-page basis, so this is so cool for super granular control over your server component loading states

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

      ​@@joshtriedcoding That's true. But the part you load lazily at the bottom could've also been loaded client side with something like SWR. I'm wondering if a server component + suspense boundary has major benefits over client-side loading.
      I wonder if search engine crawlers can see the section that's "behind" a suspense boundary 🤔

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

      @@codinginflow Ah I get what you mean, good question. To me it feels more intuitive to write on the server side, and either way they'd have to wait for the data to arrive

  • @pepew7102
    @pepew7102 ปีที่แล้ว +7

    If we would use a client component, wouldn't that also solve the problem ?

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

      yes, but why would you use a client component over a server component when you can benefit from running things on the server (you can fetch data easily with SSR)? wouldn't make your page slower with client components (no need for hooks or states which make it slower)?

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

      If you wanna get into more granular client-loading-behaviour, I 100% recommend react query (or similar) for that

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

      all of this code is running on the server, suspense is sending out the loading state in html, and when the promise resolves it sends out the images, without ever needing to transport the js bundle, hence faster

  • @Shubham-yc6nz
    @Shubham-yc6nz ปีที่แล้ว

    Super

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

    Do we not fall into this issue if we are using plain react and not next js?
    Just wondering because after the DOM is painted then we fetch the data using useEffect

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

    So the recommendations are user/client specific and only needed on the client right? So why did you not use 'use client' for the recommendation component?

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

      Because data fetching is more intuitive in server components, you ship a smaller bundle size, and handling loading and error states like this is also easier than doing it client-side. Even if react-query does an awesome job at making that easy too

  • @joshuasingh854
    @joshuasingh854 3 หลายเดือนก่อน

    This is the same as using dynamic in Next right?

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

    That’s nice, but I kind of thought you were going to propose a new UX rather than the fallback skeleton. That would be neat, like a brand new color or something.

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

    Simple but this boy is right

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

    Does suspense also work for the pages directory 🤔

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

      It's a react feature, not NextJS - so yeah. You can split components from your bundle by importing them dynamically and specify the loading behavior very granularly using suspense

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

    👍

  • @jowadev
    @jowadev ปีที่แล้ว +4

    Excellent video, why don't you mention the loading.tsx file for this purpose?

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

      Good point, guess I've used it so much at this point I assumed it as known. Probably isn't though

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

      am i correct that loading.tsx is for the whole page? so the whole page will be loading... until all datas are fetched?

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

    супер!

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

    4:02 They have it already for so long time.... I'm disappointed that typescript didn't fixed that yet.

  • @Jeridi
    @Jeridi 11 หลายเดือนก่อน

    4:54 wow

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

    so that still using server side component? I thought only client side components can use loading like that

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

      Nope, this works amazing for server components

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

    sir more project tutorials please

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

    Haven't they already fixed asynchronous components?

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

    can i do this in react with vite?

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

      yeah suspense is a react feature, not specific to next

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

    Why not iterate over the array of images itself?
    1:55
    Images.map(….

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

    Suspense and loading.jsx are different in nextjs?

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

      Suspense allows you to handle loading behavior for individual components, loading.tsx is for a certain route

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

      @@joshtriedcoding thanks my friend I subscribe now.
      Suspense is like usetransition I think.

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

    I thought the async server type error was fixed? (Not a next js / react dev)

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

      I thought so too?? No idea why this happened again. Just very recently too

  • @mohammed.haydar
    @mohammed.haydar ปีที่แล้ว

    but wouldn't it be better to have all of the data finished loading then show them to the user, this will show the user the complete fetched data instead of a bunch of loading states around the page

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

      Then you page load will be substantially longer, resulting in a worse UX. Of course you can, I wouldn’t recommend it tho

    • @mohammed.haydar
      @mohammed.haydar ปีที่แล้ว +1

      @@joshtriedcoding great explaination man. Is there a way to use Sanity to make a blog using NextJS but when I write the articles I wanna save them as .md files so that they load faster into the page? does that make sense? Because I want an easy way to modify the posts and save them as .md files so that they load much faster than fetching them from api and getting a json back. I hope I'm clear on my question

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

      @@mohammed.haydar Ahh I get what you mean. That's something I've never tried out with sanity actually. But that seems like a good use-case, even if sanity should not support that, there surely is a way to do this

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

    This still has loading states though? 😂 am I not understanding the video title?

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

      "Improperly handled loading states might be negatively affecting your user experience"

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

    Suck counter: 8 😅

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

      I dare you to turn this into a drinking game

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

    Wrong title: How to unsuck your UX

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

    Sorry was disappointed. There was no indication this is just a React solution.

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

    useTransition is also very powerful for these cases ^_^

  • @9885520844
    @9885520844 9 หลายเดือนก่อน

    Thanks for this wonderful video... I'm getting the below error while using suspense in my Nextjs project and with React 18
    Error: ReactDOMServer does not yet support Suspense.