Vue.js Advanced Component Composition Patterns

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ส.ค. 2024
  • Let's talk about Advanced Components, what patterns should you use, how can slots and JSX help? Let's take al ook!
    👉Check out my last video on Tailwind CSS 3
    • IntroducingTailwind CS...
    👉 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...
    Need to Learn Vue or Nuxt? Check out my courses below!
    bit.ly/2LalQka - Learn Nuxt.js Course!
    bit.ly/3aiYe8s - Quick Starter On Vue 3
    bit.ly/2OETt0M - Full 6 Module course on vue!
    🗂️ 🗂️ 🗂️
    Make Sure To Check These Courses From Wes Bos ! 💻
    Begginer JavaScript - BeginnerJavaScript.com/friend...
    React For Beginners - ReactForBeginners.com/friend/...
    Advanced React - AdvancedReact.com/friend/HANC...
    0:00 Introduction
    0:39 App Introduction
    2:08 Nested Slots
    5:20 Composition Store
    9:55 Render Function Pattern
    13:25 JSX Solution
    Links
    github.com/ErikCH/Vue3Advance...

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

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

    Congratulations on the 100k, Erik!
    Great video. Would love to see some similar advanced Vue content in the future!

  • @brandonleichty
    @brandonleichty 2 ปีที่แล้ว

    Congrats on reaching 100k developers! You're my #1 go-to Vue channel!

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

    Be careful with the composition store. Having reactive values outside of the setup script lifecycle can lead to nightmarish memory leaks both in the browser and in the server (if you're working in an SSR environment). I strongly advise against it. Nuxt 3 useState approach (keyed reactive refs) is by far the safest and more correct approach.

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

      That's an interesting topic! Do you, by chance, have a resource where I can read more about that?

    • @ProgramWithErik
      @ProgramWithErik  2 ปีที่แล้ว

      Hey Thanks Matteo! I have not heard of that, but that makes sense. Perhaps using something like effect Scope, could be used to mitigate that problem... v3.vuejs.org/api/effect-scope.html#effectscope

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

      @@ProgramWithErik it sure does. When you define refs/reactive values outside of setup they provide a function to have their effects disposed and garbage collected. If you don't dispose them correctly memory keeps going up every time you reload a page. I'll create a reproduction repository if you want, I have had this problem twice with two projects before understanding what was wrong 😅

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

      @@Remeroska Do you know another solution besides using Nuxt 3?

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

      And that's why StackOverflow doesn't allow (receive a lot of downvotes) when a comment like this appear. It creates a doubt on people minds, doesn't provide any proof of concept, put a lot of "facts" and just leave. When you do certain assumptions and advice people with phrases that contain a "don't do that" label is you obligation to show a least a POC showing the scenario, otherwise is just bollocks.

  • @DarylLegion
    @DarylLegion 2 ปีที่แล้ว

    Thanks Erik, great tutorial! I just started to learn Vue and in the future I might use this.

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

    Thank you Erik, amazing video

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

    100k congrats

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

    You could use

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

      Interesting! I did not know that. I'll try that next time.

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

      So it' s basically inline jsx?

  • @rajikkali2381
    @rajikkali2381 2 ปีที่แล้ว

    Global modals work great with the store pattern using an object that holds all state I want. I do it all the time and it’s infinitely customizable on the fly without limitation.

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

    Slots are cool and all, but beyond one or two levels deep they become cumbersome. So to me the store pattern is the way to go here. jsx?? I don't think so... it's what turned me off of react and onto Vue in the first place, so not about to go down that route again. Informative tutorial, thank you.

    • @ProgramWithErik
      @ProgramWithErik  2 ปีที่แล้ว

      Glad it helped~! Yeah, JSX isn't for everyone.

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

    nice! more tsx in vue? it’s a little more experimental & not as seamless as jsx in react, naturally, but vue with tsx fascinates me. there’s a couple good resources on how to work with the 2 but there’s really not a lot of content out there on it.

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

    Would you create a video about how to render a component from async content? For example...think Wordpress style short-code. Loading a vue component from HTML that is loaded from an API call. I've always wonder if there was a way to do that. I assume using the render function would be needed.

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

      Interesting, might be a fun topic to look at! Thanks I don't think I've ever done that. But I'm sure it could be done...

  • @arjunvd2277
    @arjunvd2277 2 ปีที่แล้ว

    Hi Erik,
    Can we use vue ( not vue client side ) inside already working .net core view page? is it possible? like vue packages?

    • @ProgramWithErik
      @ProgramWithErik  2 ปีที่แล้ว

      There was a conference talk at last years Vue Conference where someone was using the 'reactive' Vue on the server side. You could look into that

  • @gd9464
    @gd9464 2 ปีที่แล้ว

    Hi, I couldn't find any complete or good resource for jwt auth in vue. Can you make one with production ready. 😀

  • @edwardgwilson
    @edwardgwilson 2 ปีที่แล้ว

    Off topic question... what theme are you using in VS Code?

  • @arnesneyers2076
    @arnesneyers2076 2 ปีที่แล้ว

    You are becoming my best friend! :)

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

    Definitely want a JSX vid

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

    I think it will be a great feature for updating Hybrid apps live, without pushing a real app update into the store.

  • @RaskaTheFurry
    @RaskaTheFurry 2 ปีที่แล้ว

    I try to store all variables and methods in the root .vue file... unless they are component specific.
    like Table has sorting methods, im not gonna use that anywhere else.
    But getting data from API is at the top, because its provided everywhere and deep...

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

    It looks cool at the beginning, but you kind of open the Pandora box with the issues, I speak about experiences. Issues when you want to use events, issues when you want to use Jest, etc, ....

    • @ProgramWithErik
      @ProgramWithErik  2 ปีที่แล้ว

      That's a good point? Are you talking specifically about using JSX, or slots?

    • @artakan303
      @artakan303 2 ปีที่แล้ว

      @@ProgramWithErik JSX is problematic (maybe it's because I still use Vue2, as Vuetify is not ready yet), slots are native to Vue, so there is not issues with them.

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

    Never had to import mounted (onMounted) before… with Vue3 we write more code and it’s less readable.

  • @DedicatedManagers
    @DedicatedManagers 2 ปีที่แล้ว

    At 6:24 why don’t you just export the store variable. Why do you need a function to call to retrieve the variable.

  • @antfun8784
    @antfun8784 2 ปีที่แล้ว

    buen video crack :b

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

    Love Vue, would just like to have it render SEO friendly manner. Especially since SSR is not always an option. This I have seen done as an intercept, on routing where the SEO specific meta structure is sent when a the Google crawler bot is identified. Any ideas on something like this, as a bullet proof solution would be awesome since VueMeta is no longer applicable since the version Vue3 release.

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

      Interesting. Well first, I really like SSG so there is Vue 3 plugins for SSG like github.com/antfu/vite-ssg. As for adding meta tags vue meta is in alpha for Vue 3. Also, I think Google crawlers work fine for SPA type apps now a days. I stilll prefer SSG for the speed though on blogs and contente heavy SEO sites.

    • @SirDamatoIII
      @SirDamatoIII 2 ปีที่แล้ว

      @@ProgramWithErik Thanks for the kind reply, I will go and have a look as I am keen to find a way for static content generation (on public blog side of the app), while not touching anything behind the authenticated part of the app. My results with Vue even using Portals as per what VueMeta dev team was discussing with their upgrade for Vue3 support - was that the crawling is terrible when previewing Google bot’s scraping results. They do have a wait to load method for SPAs, but most other crawlers do not or are extremely lacking. So this is quite an interesting one as an SSR approach would best although as mentioned not always possible.

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

    Quasar ❤️

  • @caiovinicius7871
    @caiovinicius7871 2 ปีที่แล้ว

    The composition store way is magnific! I'll start to use it in my projects when necessary.

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

    I guess you could pass a component as a prop or in store and just use it in shadow box

  • @butbutmybutt
    @butbutmybutt 2 ปีที่แล้ว

    hmm, v-html?

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

    Primitive components = components which hasn'y any logic, like sections, text containers etc.?

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

      I feel like they are the lowest level of components, like buttons, text inputs, forms. Things like those I consider primitives. They may or may not have logic

    • @pathtic7397
      @pathtic7397 2 ปีที่แล้ว

      @@ProgramWithErik Ok, thanks :)

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

    Sad😕
    1. I don't want make props drilling, but I did slot drilling
    2. Not reactive as expected, and needs yous additional code
    3. Most people need time to understand this pattern, also for experience programmers. In my opinion, this pattern almost never will be using in real projects

    • @ProgramWithErik
      @ProgramWithErik  2 ปีที่แล้ว

      What pattern do you like?

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

      @@ProgramWithErik Obvious and others develops can understand. Like in official documentation

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

    9:18 onMonted is not the solution. Its because the child reasign the shadowText.

    • @ProgramWithErik
      @ProgramWithErik  2 ปีที่แล้ว

      The onMounted gives a minute for the child to load before we change the text.... There was probably a few ways to handle it

    • @studiowebselect
      @studiowebselect 2 ปีที่แล้ว

      @@ProgramWithErik yes.but it was mounted with the bad value first and was reprocess/paint after. In SSR you will have the bad text in SEO.

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

      @@ProgramWithErik btw, you are one of my favorite youtuber!

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

    First

  • @Kidziel
    @Kidziel 2 ปีที่แล้ว

    Is it only me that cannot play the video?

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

    It is very annoying to look at your folder structure in the right side

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

      In one of the video, he showed why having folder structure on the right side is better for the eyes, when you hide that, the code stays at the same place.

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

      Yeah, as @Priyank said, I put it on the right side because it's less movement when I close it of the code. I stole that from Jason at Netlify