When You SHOULDN'T Use Computed in Vue

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

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

  • @RomanDawydkin
    @RomanDawydkin 9 месяцев назад +4

    Note: it's all changed in Vue 3.4: "a substantial refactor of the reactivity system, with the goal of improving re-compute efficiency of computed properties". "With the post-3.4 optimizations, the callback now only fires if the computed result has actually changed."

  • @dCoder92
    @dCoder92 2 года назад +9

    Since vue 3 i struggle when to use composable and when not.
    Like everything could be outsourced in a composable (every api request, every state change etc.).
    It is very confusing... 🤕
    Like 80% my logic is in composables...
    Is there any tip or video that could help?

    • @nero1375
      @nero1375 2 года назад

      did you have so much logic reuse to transfer all those codes into composables?

    • @LearnVue
      @LearnVue  2 года назад +11

      When the logic is reused, that's when I try to wrap things in a composable.
      I've also seen it used as a way to just structure code so SFCs aren't massive.

    • @Ma1ne2
      @Ma1ne2 2 года назад +2

      @@LearnVue We use it in our company in both mentioned ways. For example, we have different modules in our web app. If we have shared state between the modules, we move it into a composable with global state. If we have module or even SFC specific logic and state, then we still move it into a composable with local state (not shared, newly created whenever the useX is called). As @LearnVue pointed out, this is also a great way to reduce SFC size. By that, our SFCs stay much more readable, since we move it's core logic behind an interface (the composable).

  • @fredhair
    @fredhair 2 года назад +9

    I think the real issue you highlighted is unnecessarily using a computed value as a dependency on another computed value!

    • @butbutmybutt
      @butbutmybutt 2 года назад

      yes, just use watch functions. but I think it's cleaner with eagerComputed, less code.

    • @fredhair
      @fredhair 2 года назад

      @@butbutmybutt Oh yeah, it's a nice little abstraction I guess. I don't know that it adds much imo, watch and watchEffect aren't exactly overly complex or verbose! If you're using it a lot then it could make sense.

  • @linusborg
    @linusborg 2 года назад +2

    Great Summary!

    • @LearnVue
      @LearnVue  2 года назад +1

      couldn’t have done it without a great original blog post and reactivity library 😉

  • @pawankumarthakur
    @pawankumarthakur 2 года назад +1

    Could you share the Theme name, please? Looks really nice.

  • @abdallah.s1507
    @abdallah.s1507 10 месяцев назад

    Thank you for this valuable information

  • @dbroche
    @dbroche Год назад

    thank you for sharing all the great stuff!

  • @lukmanhakim-hz4jm
    @lukmanhakim-hz4jm 2 года назад +2

    Very helpful

  • @itsmnthn
    @itsmnthn 2 года назад +7

    didn't know about this. useful

    • @LearnVue
      @LearnVue  2 года назад

      i thought it was neat too when i read the article - glad you agree :)

  • @12generalS237
    @12generalS237 2 года назад

    This is great, thank you!

  • @furkanulutas
    @furkanulutas 2 года назад

    Very nice. Thank you.

  • @yanDev
    @yanDev 2 года назад

    very interesting!
    Thanks

  • @ilya.degtyarenko
    @ilya.degtyarenko 2 года назад

    Thanks 💛💙

  • @jingzheshan
    @jingzheshan 2 года назад

    Thanks for sharing!

    • @LearnVue
      @LearnVue  2 года назад

      Thanks for watching!

  • @jameswrightson744
    @jameswrightson744 2 года назад +2

    "When You SHOULDN'T Use Computed in Vue" - "In a few cases"

    • @jhblack23
      @jhblack23 2 года назад

      The title is a better clickbait like that 😆

    • @jameswrightson744
      @jameswrightson744 2 года назад

      @@jhblack23 not click bait, he provides very little reason not to use it

    • @LearnVue
      @LearnVue  2 года назад +2

      lol the title was too good to pass up.
      i think the use case is 3:46 where you have an expensive operation that relies on a simple computed property is the main summary from a title -> answer perspective.
      the default use and optimizations for computed is still good to handle a majority of use cases, but at least for me - learning about eager computed taught me a lot about the specifics of how vue computed caches and updates.

  • @videolucu5900
    @videolucu5900 2 года назад

    GOD!!!My broo

  • @MartinMasevski
    @MartinMasevski 2 года назад

    Interesting 🐱

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

    This is outdated. Can't replicate it on Vue 3.5

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

      Yeah this is actually the default on 3.4+ blog.vuejs.org/posts/vue-3-4#more-efficient-reactivity-system

  • @Linkplay9
    @Linkplay9 2 года назад

    just do $: expensiveCalculation(count) and you will be good
    keep calm and use svelte