【发布时间】:2021-07-06 03:02:37
【问题描述】:
我在使用 react-hook-form v7 + material-ui 文本字段时遇到问题。如果我设置 autoFocus 或手动更改文本字段值,则 defaultValue 有效。但是,如果我只是提交而不用鼠标单击不是自动对焦的文件,则在表单提交期间 defaultValue 消失了。请查看codesandbox link
我的问题是如何让这个默认值始终提交,即使没有鼠标点击或更改 textField 的值?
请提前帮助和感谢
【问题讨论】:
-
感谢@micFung 解决方案。这个问题的主要问题是 material-ui 和 react-hook-form 使用不同的键 inputRef 和 ref。有2个解决方案 1.使用react form controller codesandbox.io/s/… 2.手动映射inputRef和ref codesandbox.io/s/…
标签: reactjs typescript material-ui textfield react-hook-form