英文:
defaultValue react hook form doesnt receive object.data
问题
I'm using React Hook Form to make some Edit/Update data, getting my data from Zustand, with a type value of any. then I save it to defaultValue from React Hook Form, I'm getting 'Undefined' when I get values, but when I manually hardcode it with some strings and numbers, it can be correctly getValues like I hardcode it.
What recently I updated is changing the data type from Zustand to the data model type from Prisma, where I got it from the 'Report' table, but the same, nothing changed. I'm doing console log to some inputs, it still gets 'undefined'.
Can someone help me please?
FINAL RESULT
it was the first render, I need to add useEffect to update the value, and inside, I need to call the reset() API.
英文:
I'm using React Hook Form to make some Edit/Update data, getting my data from zustand, with type value any. then I save it to defaultValue from React Hook Form, I'm getting 'Undefined' when get values, but when I manually hardcode it with some strings and numbers it can be correctly getValues like I hardcode it.
What recently I update is changing type data from zustand to type data model from Prisma, where I got from table 'Report', but same nothing changed. I'm doing console log to some inputs it still get 'undefined'
Can someone help me please?
FINAL RESULT
it was first render, I need to add useEffect to update the value, and inside I need to call reset() API.
答案1
得分: 1
defaultValues
只在第一次渲染时应用。看起来它在第一次渲染时应用了来自报告对象的值。
对于后续的渲染,如果您想要更新表单值,您可以使用setValue。
英文:
defaultValues
only apply during first render. It seems it is applying the values from report object during first render.
For subsequent render if you want to update the form values you can use setValue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论