Let me show you how to *steal* prop types in @vuejs.

I often find that I'm copying prop types from a child component to a parent.

For example, we have an `Icon` component being used in this component:

#webdevelopment Image
To get this to work, we need to add the correct prop types, copying from the `Icon` component: Image
What a pain.

And when the prop types of the `Icon` component are updated, you can be *sure* that you'll forget to come back to this component and update them. Image
Over time bugs will be introduced as the prop types for this component start to drift away from the prop types in the `Icon` component.

So that's why we'll *steal them* instead:
It doesn't have to get any more complicated than that!

But if you want, you can also dynamically update the name of the props to prepend "icon" on to the name of each, so it matches what we had in the original example.
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

• • •

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

Mar 14
Did you know you can write reactive CSS in @vuejs 3?

We can use reactive values in our `<style>` block just like we can in the `<template>` block:

#webdevelopment Image
Behind the scenes Vue uses CSS custom properties (aka CSS variables) that are scoped to each component.

This way the CSS remains static, but we can dynamically update the CSS variables whenever the reactive value changes.
More info can be found in the docs:

v3.vuejs.org/api/sfc-style.…
Read 4 tweets
Nov 9, 2021
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 13 tweets
Nov 7, 2021
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.
Read 4 tweets
Oct 21, 2021
1/ Did you know that you can destructure in a `v-for` in @vuejs? Image
2/ It's more widely known that you can grab the index out of the v-for by using a tuple like this: Image
3/ When using an object you can also grab the key: Image
Read 5 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(