Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What are the most important differences to note between ref and reactive in vuejs?

I learned vuejs recently and I seem to be having problems in fully grasping the essential differences between the usage of ref and reactive. When is it right to use ref or reactive?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Based on this article from Anthony Fu (a Vue.js champion) we can summarize it in these points:

  • refs are considered as primitives values
  • reactives as objects
  • refs only mutated by .value property, but reactive with any nested property
  • reactives looks like plain objects
  • reactive objects have some caveats like loosing reactivity when they are destructed.
  • reactive objects should be wrapped with function when they’re watched like watch(()=>reactiveObj,(newVal,oldVal)...., unlike refs which are unwrapped watch(refProp,(newVal,oldVal)....

Conclusion :

I’d say go with ref whenever you can

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading