This is how you master computed props in @vuejs 👇🏻

When a function does more than just return a value, it makes your code more complicated.

These are called side effects, and you should never have them inside of a computed prop: Image
But we can fix this.

We can move that side effect into a watcher that is triggered whenever the computed prop updates: Image
Note: This technique applies equally to the composition API, although the syntax is slightly different.

At first glance, this may seem like we made the code more complicated. But actually, we've made it a lot simpler.
This excerpt from my course, Clean Components, explains this in more detail:

michaelnthiessen.com/side-effect-su…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Michael Thiessen

Michael Thiessen Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @MichaelThiessen

9 Nov
Here's a mega-thread of my best @vuejs tips.

Enjoy, retweet, and let me know what you think!
If you want more @vuejs tips like this, I send out a newsletter with tips and insights on using Vue every week.

"This is the first time where I'm actually enjoying email newsletters" — Fahmi

Sign up here michaelnthiessen.com/newsletter
Read 12 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(