Skip to content

Why is console.log(toReactive(ref([]))) returning {} instead of [] ? #4825

Answered by dosubot bot
tricaric asked this question in Q&A
Discussion options

You must be logged in to vote

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 pass ref([]), 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, use reactive(ref([]).value) or just reactive([]) instead. The current API doesn't support array refs for toReactive—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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tricaric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy