Vue.js Advanced Data Provider Component Patterns Explained

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • 🚨 Check out this 100% free Vue.js conference! vuejsnation.com/
    In Vue you can create renderless functions that provide a data access provider pattern. In this video we explain how to create one of those using Fetch. Then we compare it to the composition API with composables using the vueuse composable for Fetch. #vuejs
    👉Check out my last video on why you don't need Vue.js Options API
    • Why You Don't Need The...
    👉 Sign up and get free Vue cheat sheets and updates!
    www.vuecourse.tech/
    Need some mentoring, help with a project, get a career in tech, level up your skills? Check it out
    👉mentorcruise.com/mentor/erikh...
    0:00 Introduction
    0:37 Vuejs Nation
    01:26 Fetch-json renderless component
    08:19 Quick Tips on Slots
    08:47 Composable Pattern VueUse
    11:16 Bonus Bonus Bonus!
    Links
    vuejsnation.com/
    gist.github.com/ErikCH/4fc18b...
    gist.github.com/ErikCH/5185ad...
    * this video was sponsored by VuejsNation! Thanks Vuejs nation!

Komentáře • 47

  • @ProgramWithErik
    @ProgramWithErik  Před 2 lety +7

    vuejsnation.com/
    The first 100% FREE Vue.js Conference is around the corner! 🎉
    Join the @vuejsnation and explore the vast @vuejs ecosystem in 2022!
    Date: 26th & 27th January
    Tickets: FREE ✅
    Interact with industry leaders LIVE including Evan You and Sebastien Chopin!

    • @MartinOmander
      @MartinOmander Před 2 lety

      I had not heard of this conference before. Thanks for bringing it up in your video, Erik!

    • @cnikolov
      @cnikolov Před 2 lety

      See you there

    • @Microphunktv-jb3kj
      @Microphunktv-jb3kj Před rokem

      internal data provider like this ive seen in vue3 ui libraries, like naiveui and elementplus i think.
      "config provider" , the concept is the same i guess?

  • @abdallahalsahhar9511
    @abdallahalsahhar9511 Před 2 lety +1

    about a week ago spent a day trying to do renderless script setup with no success, Thanks a lot @Erik

  • @gideaoferreira8236
    @gideaoferreira8236 Před 3 měsíci

    You are amazing, Erik. Thanks!

  • @kaibe5241
    @kaibe5241 Před 2 lety +4

    Pretty interesting way of managing data requests, but I think I'll stick to my domain repositories.

  • @norielarguelles110
    @norielarguelles110 Před 2 lety

    nice vid Erik!

  • @MrSanya789
    @MrSanya789 Před 2 lety +4

    Hi Erick, thanks for the video. I used this pattern a lot on my current Vue 2 project and find it very useful. I always write it with template section like this:
    As for me, it is a bit simpler than context usage.

  • @chris_ea
    @chris_ea Před 2 lety

    🏆 absolutely useable!!!!

  • @DarylLegion
    @DarylLegion Před 2 lety

    Thanks Erik!

  • @dmitriykret8938
    @dmitriykret8938 Před 2 lety

    so helpful 👍

  • @binodnepali
    @binodnepali Před 2 lety

    Hey Erik, do you have a video about your VIM setup in VS code?

  • @cnikolov
    @cnikolov Před 2 lety +1

    Use fetch and the Utility lib looks very good, I would still wrap it to composable or something so I can use typescript to marry the types

  • @andrewananenko797
    @andrewananenko797 Před 2 lety

    Sorry for question, What do you constantly try to look for aside?

  • @Technologism
    @Technologism Před rokem

    What theme or extension do you use to make the function name so bright

  • @andrewananenko797
    @andrewananenko797 Před 2 lety +1

    Maybe i am wrong, but why use this way if we have with default slot and #fallback for loading indicator? does the same but greatly easier. Thank you for the video!

  • @MilenkoCurcin
    @MilenkoCurcin Před 2 lety

    Can you also create an example with posting data instead of fetching? A great video, btw

  • @JanisWalliser
    @JanisWalliser Před 2 lety +1

    Not so sure if I would call a component that literally uses the render function to render a slot "render less". Maybe I am missing something tho.
    Also one point not mentioned which I think counts for the composable way is that it is usable outside of Vue. E.g. in a App that is not Vue only you can still use that composable function just without reactivity.

    • @ProgramWithErik
      @ProgramWithErik  Před 2 lety +1

      Well, it's rendering a slot, which I feel like is enough to call it renderless. I Adam Wathan coined it, in his Advanced Vue course. Interesting, I haven't though of that definition of composable.

  • @emmyleke7049
    @emmyleke7049 Před 2 lety

    Hi Erik, what text extension do you use on VSCode that makes your arrow functions look like arrows.

    • @JesusMRamosPerez
      @JesusMRamosPerez Před rokem

      I believe that is firacode font. I have been using it for a while and it looks great.

    • @charlesm.2604
      @charlesm.2604 Před rokem

      Any ligature compatible font will do, JetBrains Mono is by far my favorite.

  • @chris_ea
    @chris_ea Před 2 lety

    Can you show a example by using axios instead of fetch?

  • @josehermosillarodrigo1795

    Why don't you just use a template tag to render the default slot and bind data? I think it's easily to work with, instead of dealing with render functions. Something like:

    • @ProgramWithErik
      @ProgramWithErik  Před 2 lety

      I used a renderless function witha v-slot. I then did it without the template tags. Look at 07:02

  • @MartinOmander
    @MartinOmander Před 2 lety

    I appreciate seeing a new way of calling APIs. But why do extra work to put the fetch code in a component, instead of simply importing a util file which exports a plain old function? I'm genuinely curious.

    • @blank4157
      @blank4157 Před 2 lety +1

      I think he used it for the sake of explaining the concept i.e renderless components.
      I would still prefer plain old functions for api calls (I usually call them services) since they can be used anywhere in your js code and not just inside templates.

    • @MartinOmander
      @MartinOmander Před 2 lety +2

      @@blank4157 Good point!
      I did some more online searching of why one might want to put code in renderless components, as this was a mystery to me. Some people say that renderless components are easier for UI developers to use. A Javascript developer would implement the component. Then a UI developer can add it to layouts by simply adding tags. Presumably they are more comfortable with HTML-like tags than with raw Javascript code.
      As I am more of a Javascript developer and less of a UI developer, it could be that this technique simply isn't aimed at people like me.

    • @ProgramWithErik
      @ProgramWithErik  Před 2 lety +1

      Great points already in the comments here, but as I said in the video, it could also be that you'd like to use the full power of Vue, and be able to Reactive variables, and lifecycle hooks and everything Vue has to offer. So wrapping it in a component makes sense.
      Being good for designers is another good point.

    • @MartinOmander
      @MartinOmander Před 2 lety

      @@ProgramWithErik What you said about using reactive variables and lifecycle hooks makes sense. Thanks for the clarification!

  • @Shmidtelson
    @Shmidtelson Před 2 lety

    Bro why are you using any type with props?

  • @volodymyrkozliuk6811
    @volodymyrkozliuk6811 Před rokem

    I really like your brackets theme. What is it called?😀

  • @rajikkali2381
    @rajikkali2381 Před 2 lety +2

    I prefer managing it all in Vuex

    • @MartinOmander
      @MartinOmander Před 2 lety

      Me too. Then any component can access the data that was fetched from the server.

  • @glowiever
    @glowiever Před 2 lety

    this is like contextprovider in react

  • @brokula1312
    @brokula1312 Před 2 lety +2

    It's more of a hack than useful tool. Greatest drawback is that you are pushing the logic inside the template and by using slots you loose type safety....so rather just use plain ol' composition API.

    • @ProgramWithErik
      @ProgramWithErik  Před 2 lety

      That's why I showed both ways, so it is good to compare and contrast.

  • @ignisAnimus
    @ignisAnimus Před 2 lety

    Nice idea, but I wouldn't do it that way.

  • @richardstiller9492
    @richardstiller9492 Před 2 lety

    Vue has good concepts, if it avoid its vue files, it will be useful.