defaultValue在React Hook Form中未接收到object.data。

huangapple go评论69阅读模式
英文:

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.

defaultValue在React Hook Form中未接收到object.data。

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

huangapple
  • 本文由 发表于 2023年6月8日 12:16:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定