1

I'm a begginer vue developer. In vue composition api when you want to create a reactive variable with object source value, you can use both "ref" and "reactive", for example:

const a = ref({ x: 'hi' });
let b = reactive({ x: 'hi' });

// reassignment
a.value.x = 'hello';
Object.assign(b, { x: 'hello' });

note that b.x = 'hello' will remove reactivity from b, so according to my little experience use "ref" instead of "reactive", can satisfy all requirements you need, so the real question for me is this "Why we do not remove "reactive" from all our codes?"

With my little knowledge in "vue" using "reactive" will add more potential mistakes to our codes and I don't understand real benefits of using "reactive" against "ref".

  • The best answer https://stackoverflow.com/a/65262638/2487565 to the topic "ref vs reactive in Vue" – Tolbxela Jun 28 '23 at 13:01
  • @Tolbxela but this does not answer: "Why we do not remove "reactive" from all our codes?" – mohammad asghari Jul 20 '23 at 08:45
  • @mohammadasghari 1. `reactive` ist easier to use and shorter to write without `.value`, 2. rewriting the whole codebase with about no benefit does not make much sense. – Tolbxela Jul 20 '23 at 09:14
  • @Tolbxela First of all, thank you for your attention. These reasons are absolutely true, but I'm looking for the more technical goals of the Vue development team. Is it reasonable to split the definition of reactive variables only for code style reasons? – ahmad zahedi Jul 22 '23 at 06:53

0 Answers0