reactjs - Material UI AutoComplete 设置值为 0
问题描述
我一直在这个错误上停留了一段时间,不知道发生了什么,如果你有第二个,请你帮忙。谢谢你。
问题:
- 我正在尝试将自动完成组件与材料 ui 和 react-hook-form 一起使用,但是每当我从下拉菜单中选择一个选项并从 reack-hoom-form 监视功能中记录值时,即使选项也被记录为 0是字符串。
我已经在codesandbox上复制了这个问题,请参阅下面的链接 https://codesandbox.io/s/material-not-working-her-weg6e?file=/src/App.js
解决方案
你的代码沙箱里有很多与问题无关的不需要的代码。我已经把它清理干净了。
初始化状态 -
const [inputValue, setInputValue] = React.useState("");
OnChange,更新状态
onChange={(e, data) => { setInputValue(data.year); }}
这是一个记录所选分辨率代码 代码沙箱值的工作代码
推荐阅读
- javascript - 如何使用扑克骰子生成五种或满屋?
- java - 无法下载文件:无法解析为 URL,因为它不存在
- php - 缩短 Woocommerce 存档页面上的产品标题
- mql4 - 交易量返回不正确的值 MQL
- wordpress - 如何为 Wordpress 的开发人员提供受限访问权限
- node.js - 只需将对象中的任何数据存储到表中,而不管它具有什么结构?
- dependency-injection - Azure Functions 依赖注入再次失败
- java - 在Java中将一个整数列表拆分为两个长度大致相同的列表
- python - 如何在 Python 中为列表中的多个分组生成排列
- c# - 多绑定中的 DependencyProperty.unsetValue