mutating object props utilizing toRef() - why is it bad practice? (example included) #9256
Replies: 3 comments 5 replies
-
Just found https://medium.com/@hl037.prog/vue-js-props-mutating-how-an-anti-pattern-could-be-considered-a-good-practice-84fcb890d364 - exactly my thoughts... |
Beta Was this translation helpful? Give feedback.
-
We have also faced this same situation with toRefs. We cannot assign any value to the refs as it is restricted for props. And since we already can get the updated props value by simply assigning the defineProps to a constant like, "props" and calling the props as props.someprop, why even there's a documentation on using toRefs or toRef with props when the main purpose of using refs is not served? |
Beta Was this translation helpful? Give feedback.
-
I would also like to know if this cause any nasty side effects or performance issues. so far in my testing this doesn't cause any issues. Just wondering the "vue/no-mutating-props" is a thing of the past with introduction of fine grained reactive fundamentals. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
ESLint gives the error "vue/no-mutating-props" if props are directly mutated (not the case in the Vue SFC Playground, but never mind).
This error can be avoided by using toRef().
However: (quoted from there)
I've created a small example in the Vue SFC Playground and I just don't understand what's wrong with it doing it this way.
I experience this case (also described by @zeodtr in discussion #6039) each and every day in our (rather large) vue project - and I handle it as shown without any problems so far.
If this is "not allowed", then why is it not prevented in the first place? (but please don't do that ;-))
Beta Was this translation helpful? Give feedback.
All reactions