Skip to content

fix: watch() logic typeof check on array is always false #849

Closed
@hichem-dahi

Description

@hichem-dahi

🐛 The bug

That code is watching an array but checking if the whole array is a string/number

watch(
() => [props.revision, props.state],
(value) => {
if (typeof value !== 'number' && typeof value !== 'string')
deepSync(value, props.state)
else
proxy.value = props.state

🛠️ To reproduce

https://stackblitz.com/~/github.com/kleinpetr/nuxt-playground/tree/devtools-usestate-reactivity

🌈 Expected behavior

If props.state is a primitive (like a number, string, boolean, etc.), use the else branch. If it’s an object or array, use the if branch and call deepSync.

ℹ️ Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions