N
Nuxt3mo ago
Nisthar

why isn't input's value not updating when using useState value in it?

guys i have a useState that doesn't have any values, it later gets set to an object after a fetch request to an api But if i use this useState object's value for an input, the input value is always empty
<Input id="account-id" :value="user.id" />
<Input id="account-id" :value="user.id" />
export const useUser = (): Ref<UserType> =>
useState<UserType>('myapp.user')
export const useUser = (): Ref<UserType> =>
useState<UserType>('myapp.user')
const user = useUser() anyone know why the input's value never changes when the useState changes?
8 Replies
manniL
manniL3mo ago
export const useUser = () => useState<UserType>('myapp.user')
export const useUser = () => useState<UserType>('myapp.user')
should be a function and it should return the currently set value yeah, I wouldn't type it this way
Nisthar
NistharOP3mo ago
how is this different from the code? aren't they both the same?
manniL
manniL3mo ago
@Nisthar that was mainly as an answer to @l422y. Code seems fine except that you don't have 2-way binding (e.g. with v-model) or reacthing on an @input event that's why the input component never changes the state
Nisthar
NistharOP2mo ago
but doesn't the input need to update when the value changes even if it is one way binding? using v-model works, but i don't know why :value doesn't work for this
KirbyTwister
KirbyTwister2mo ago
One way binding implies that when A changes, then B changes too But not the other way around
manniL
manniL2mo ago
is it a typical HTML input?
Nisthar
NistharOP2mo ago
No its a shadcn-vue input component. It might be why its not working Yes i was expecting the input changes when the state changes
manniL
manniL2mo ago
you might want to look up how you pass initial values into that (default via the modelValue prop if a simple v-model is used)
Want results from more Discord servers?
Add your server