-
I am converting a ref to an empty array to a reactive, and noticed that if I try to do it with VueUse' toReactive(), I get an empty object {}, while if I explicitly pass the .value, I get an empty array []:
Is this expected? I am confused, as I would have expected an empty array in both cases.
on node (v24) gives me an error, i.e.:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @tricaric! I'm Dosu and I’m helping the vueuse team. This is expected: To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Hi @tricaric! I'm Dosu and I’m helping the vueuse team.
This is expected:
toReactive
is designed for refs containing plain objects, not arrays. Internally, it creates a proxy with an empty object as the target, which means when you passref([])
, the result is an object ({}
), not an array ([]
). This breaks array methods and can cause errors like the stack overflow you saw. If you want a reactive array, usereactive(ref([]).value)
or justreactive([])
instead. The current API doesn't support array refs fortoReactive
—it's intended for objects only, as shown in the implementation and tests see source.To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hal…