useAsyncData vs. useFetch 🤯

Поделиться
HTML-код
  • Опубликовано: 9 янв 2025

Комментарии • 73

  • @valacshiro378
    @valacshiro378 10 месяцев назад +3

    Thank you again, I really like your videos and examples, even though I watched all it will be helpful to include the link or the video when you mention it :)
    Thanks again for keeping it going 🙏

    • @TheAlexLichter
      @TheAlexLichter  9 месяцев назад

      Thanks for the suggestion! I include all links in the descriptions and videos as cards in the corner of the video (+ in the description ☺️)

  • @KefiVitcH
    @KefiVitcH 10 месяцев назад +2

    Your content is great and the way you explain things is awesome ! here is a small advice: thhe noise cancelling is cutting some words some time. You may need to reduce it ;)

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад +1

      Thanks for the tip! Will revisit my gate settings 👌

  • @barbapapazes
    @barbapapazes 10 месяцев назад +2

    Perfect explanation once again! 👌

  • @QueeeeenZ
    @QueeeeenZ 10 месяцев назад +1

    It would also be nice to see how to build useAsyncData from scratch and how it works under the hood.

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Great idea! Added to the list 👌

  • @virusblitz
    @virusblitz 10 месяцев назад +1

    Amazing video as alsways! Perfect topic as always :D

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад +1

      Glad you think so! 👌
      Let me know if you have any ideas or topics in mind!

  • @codewithguillaume
    @codewithguillaume 10 месяцев назад +2

    Yess!!!!!

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Haha, waited for this one for a while? 😁

  • @AksoomHussain7866
    @AksoomHussain7866 10 месяцев назад

    your videos are great help to understand behind seen, nowadays i see most nuxt video cover composables and predefined function majorly , i would like you to explore layouts as it seem less explored part of nuxt like implementing persistence layout, nested layout and hook functions in nuxt, may be your tricks help in IRL work

    • @TheAlexLichter
      @TheAlexLichter  9 месяцев назад

      Glad they help 🙏🏻
      I put nested layouts on the list 👍🏻
      Hooks are also interesting but they need specific use cases ☺️

  • @shuanwang4227
    @shuanwang4227 10 месяцев назад +1

    This is very helpful! Thank you always.

  • @seiidkhandzhursumbekov1013
    @seiidkhandzhursumbekov1013 25 дней назад

    Could you please provide a link to source code of app shown in the video? I wanna save it for future reference

  • @MrSimpleCF
    @MrSimpleCF 10 месяцев назад

    I love you man, always helpful and super insightful

    • @TheAlexLichter
      @TheAlexLichter  9 месяцев назад

      You are welcome! Glad I can help 🙏🏻

  • @nhs119nhs119
    @nhs119nhs119 10 месяцев назад

    Like your videos more and more, great job as always!

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Thank you very much! Is there anything on your mind that could be better? 😊

  • @buxtehude578
    @buxtehude578 10 месяцев назад

    Thank you. Could you kindly elaborate on why the useFetch function isn't universally applicable? It feels like a design flaw ... akin to React's approach, requiring users to be aware of specific exceptions, e.g. when dealing with all of their hooks.

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      What exactly do you mean with "isn't universally applicable"? That you can only use it in a Vue context? 👀
      (Related: ruclips.net/video/njsGVmcWviY/видео.html )

    • @buxtehude578
      @buxtehude578 10 месяцев назад

      @@TheAlexLichter Thank you for getting back. As highlighted in both the documentation and the video, it's emphasized that useFetch is intended for data fetching in a component setup function, while $fetch is better suited for making network requests triggered by user interaction.

  • @ElTebe
    @ElTebe 10 месяцев назад

    How can the above methods be leveraged, for example, in the case of an AWS Amplify GraphQL call?

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Same idea, but using POST. I'd probably use a dedicated GQL lib/module though

  • @gomesbruno201
    @gomesbruno201 4 месяца назад

    so, is useAsyncData like react's useMemo with a different life cycle?

  • @chstappert
    @chstappert 10 месяцев назад +1

    Thanks a lot for this important insight!

  • @Дмитрий-л4с9х
    @Дмитрий-л4с9х 4 месяца назад +1

    Thank you for your video!
    Could you please give me an advice. I wanna make the app which can be managed in both directions: if i change my reactives, data will changes and if i come from another page with pre-set query, the data should be correct. Struggling with that 😵
    P.s. Using useAsyncData

    • @TheAlexLichter
      @TheAlexLichter  4 месяца назад

      You are welcome!
      Both ways should work by "watching" the route query I'd say 🤔

  • @alimaher1
    @alimaher1 10 месяцев назад +1

    As always, great content! Also, I have a question; Is it okay to use Nuxt with complete Client side rendering (Full SPA)? In my work, they can't afford ssr, should I go with nuxt to get all the benefits or it would be overhead?

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Yes, absolutely! You can build a plain old SPA with Nuxt if you don't need SSR!

  • @_parassolanki
    @_parassolanki 10 месяцев назад

    It would be nice to have composable for mutation like `useMutation` available in tanstack query currently for mutation we can't use useFetch and it does not success, error callbacks.

    • @TheAlexLichter
      @TheAlexLichter  9 месяцев назад

      You could use useFetch with interceptors though, couldn't you? 🤔

  • @jordivandermeer601
    @jordivandermeer601 27 дней назад

    Thanks for the video. I am still little confused between the ways to do fetching. I am still learning a lot. Mabe a video for beginners? Why not always use useasyncfetch?

    • @TheAlexLichter
      @TheAlexLichter  27 дней назад

      Which one do you mean
      Why not always use useFetch?
      Or
      Why not always use useAsyncData?
      👀

    • @jordivandermeer601
      @jordivandermeer601 27 дней назад

      @TheAlexLichter hi. Yes for example I use the nuxt supabase module. And fetch some data. What is best practice for example? The example in the document uses useasync data. I also red that usefetch caches the data? Or when I fetch data from a own server api I just use /fetch. That also works fine? Lot of questions haha

    • @seiidkhandzhursumbekov1013
      @seiidkhandzhursumbekov1013 25 дней назад

      @@TheAlexLichter Hello. Could you please provide a link to source code of app shown in the video? I wanna save it for future reference

  • @Tarabass
    @Tarabass 10 месяцев назад +1

    Nice video, as always! How do you do that, talking at conferences and posting video's on yt at the same time lol 😅

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад +1

      Haha, just because I am not there I can't let the people wait for the content 😁
      Though I didn't do many announcements around (will do that on Monday)
      Was nice meeting you in person!

  • @jahongirsalimov9587
    @jahongirsalimov9587 10 месяцев назад +1

    awesome as usual! Thank you !

  • @LB-q7m
    @LB-q7m 3 месяца назад

    Hi great tutorial. I am using useAsyncData with a handler function that performs multiple $fetch's within to populate page data (as I am hitting a few different apis). But when in my /server/api route I am seeing it is getting called twice. Any ideas on a solution?

    • @TheAlexLichter
      @TheAlexLichter  3 месяца назад +1

      Do you possibly have 2 components calling the same API?

    • @LB-q7m
      @LB-q7m 3 месяца назад

      @@TheAlexLichter I think I got the issue sorted on dev mode. But I notice on prod it's hitting the API twice, almost like it's rendering the page twice or hitting it client and server side at the same time.

  • @elviskemboi7668
    @elviskemboi7668 10 месяцев назад

    am trying to use fetch with a laravelapi and when i run my nuxt app i get that useFetch component has already been mounted see the $fetch what can i do about this

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      My video about useFetch should help you there! ruclips.net/video/njsGVmcWviY/видео.html 🙌

  • @DavidDeSloovere
    @DavidDeSloovere 10 месяцев назад +1

    For other that may wonder, I asked copilot “Why the name $fetch?” Instead of ofetch:
    - The name $fetch is chosen for consistency and ease of use.
    - It aligns with Vue’s convention of prefixing instance properties with a dollar sign (e.g., $data, $props, $emit).

  • @freekeys
    @freekeys 6 месяцев назад +2

    useAsyncData is more like useEffect in react that has watcher

  • @barbapapazes
    @barbapapazes 10 месяцев назад +1

    That thumbnail is so fun 😂

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад +1

      A hilarious one every now and then 😛

  • @vensonhunt
    @vensonhunt 9 месяцев назад

    if the url is build upon query, which is not the options of useFetch, how to make it work

    • @TheAlexLichter
      @TheAlexLichter  9 месяцев назад

      How do you mean that? You can pass it to useFetch anyway ☺️

  • @ArnoldGotClips
    @ArnoldGotClips 10 месяцев назад +1

    'DX' is short form for what?

  • @gabrielserejo8379
    @gabrielserejo8379 10 месяцев назад +1

    nice video alex!

  • @DevMarques
    @DevMarques 10 месяцев назад

    Great video as always.
    How would you leverage useFetch with a repository pattern? My whole repository file is sustained on something like this and the same query might at some point be triggered by user interaction (which triggers a warning when using useFetch) or just plain data fetching (which works just fine):
    import type {$Fetch, NitroFetchRequest} from 'nitropack'
    import type {ApiResponse, ApiResponseWithCursorMeta} from "~/types/responses.generics.interface";
    export const eventsRepository = (fetch: $Fetch) => ({
    async get(cursor: null | string = null): Promise {
    let url = '/events/';
    if (cursor) { url += `?cursor=${cursor}` }
    return fetch(url)
    },
    })

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Thank you!
      I'd go with useAsyncData as shown in ruclips.net/video/jXH8Tr-exhI/видео.html 😊

  • @fmoessle
    @fmoessle 10 месяцев назад +1

    as always: thank you :)

  • @yoskokleng3658
    @yoskokleng3658 3 месяца назад

    so headache, i would use axios instead :)).

    • @TheAlexLichter
      @TheAlexLichter  3 месяца назад

      Keep in mind that axios is comparable to $fetch but not to the fetching composables like useFetch or useAsyncData

  • @mr.developer617
    @mr.developer617 7 месяцев назад

    Thank You

  • @nanaassumadu4997
    @nanaassumadu4997 10 месяцев назад

    ow God I love you

  • @jurarexx
    @jurarexx 10 месяцев назад +1

    • @TheAlexLichter
      @TheAlexLichter  10 месяцев назад

      Because it is checked (up to) 3x in the code 😊
      Does that cause an issue?
      I briefly talked about that in ruclips.net/video/Tu9R074zPz0/видео.html too 🙌