Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

is reactive() just a mere wrapper around ref() ?



Kind of -- reactive() lets you declare multiple values at once, and you can read the property directly.

ref() is for single values, and to get at the actual VALUE, you need to use "myRef.value"

   const state = reactive({ msg: "hello", count: 1 })
   state.msg // "hello"
   
   const msg = ref("hello")
   msg.value // "hello"
Though when you use ref()'s in templates, it will bind to .value for you.


I find myself using `const state = reactive({...})` exclusively now. It's just way simpler (read:less mental overhead). But, I've only been using the composition API for a short while now.

Do experienced Vue devs actually use both regularly?


Personally, I rarely use refs. I think they have more use when creating general-purpose libraries for Vue.

You can also just call "toRefs()" on a "reactive()" object though.

Refs are also useful if you want to destructure a reactive object without breaking the reactivity, scroll down just below this:

https://composition-api.vuejs.org/api.html#torefs


According to the vue discord where I asked a lot of composition API questions, pretty much people use ref exclusively. It's much more explicit in your `use*` composition files when you have to call .value. It's rare to me to export a very large object of keys, and I have yet to use it yet.


Other way around I think. ref is a single value reactive.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: