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

What is the `10` here? Is it a reference to the literal value `10`...?


It is just an initial value.


So ref is just a state variable with an initial value of 10? How do you mutate the variable/change the state?


No, $ref(10) will return a reactive object. And 10 will be the initial value of that object.

You use the object the same way you use a js variable.

let st = $ref(10)

st = st + 1 // update it and use it like if it was just "10"

But now, st is reactive.


Thank you for the explanation... I will have to learn a lot of basics, it looks like :)




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: