$attrs is reactive in Vue3 composition API, but the docs say they aren't. #12233
Replies: 4 comments 2 replies
-
|
I assume you refer to this paragraph:
This is not in contradiction to what you are experiencing, though the wording could be improved I guess. The last sentence indirectly explains what you are experiencing:
To put this in more explicit terms:
So both things are correct:
Well, if a change from the parent would not reflect in the child, that would make |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, this is not an answer, I should have sent it as a reply. ArchivedI appreciate the explanation. That said, I’m still struggling a bit with the mental model. I fail to produce any functional difference in behavior between `attrs` and `props` other than `isReactive`. For all intents and purposes, they walk and quack exactly the same. `watch` and `computed` working perfectly in practice, being told it "isn't reactive" feels like a riddle. I’d love to see a clear table of comparison in the docs to help bridge this gap. If the difference is purely internal implementation, it would go a long way in clearing this up for everyone.Playgrounds: |
Beta Was this translation helpful? Give feedback.
-
|
I think the difference is that when attributes change, a whole re-render is triggered, instead of a partial one (which would happen when a prop changed). The fact that it feels reactive is because the setup function is ran again. But I'm also struggling with the onUpdated, which feels useless if the component rerenders anyway? I guess this boils down to a theoretical vs. practical difference? But I might be completely wrong of course 😅 |
Beta Was this translation helpful? Give feedback.
-
ArchivedSetup function is NOT ran again, at least not in the playgrounds I shared. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Are the docs incorrect, or is this actually an internal bug?
When we apply
$attrs.classfor example, it changes when the parent's:classupdates, which, according to the docs, shouldn't happen.We don't want to use this if it's actually a bug.
Beta Was this translation helpful? Give feedback.
All reactions