Is "ref" better than "reactive" for create reactive variable with object source value in vue 3?

63 Views Asked by At

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".

0

There are 0 best solutions below