reactjs - 尝试设置输入属性时反应useRef返回未定义的错误
问题描述
我已经使用了来自 react 的 useRef 钩子
const myInput = useRef()
并将其传递给 material-ui OutlinedInput 组件
<OutlinedInput
id="outlined-adornment-amount"
inputRef={myInput}
type="file"
startAdornment={<InputAdornment position="start">
<FolderIcon fill="#333" />
</InputAdornment>}
labelWidth={60}
/>
当我尝试在 useEffect 中设置输入的属性时
useEffect(() => {
myInput.current.directory = true
}, [])
我明白了
未捕获的类型错误:无法设置未定义的属性“目录”
解决方案
我看不出你的代码有任何问题。我测试过,一切正常。看看这个:
推荐阅读
- python - 如何在 python 中的进程之间共享数据?
- alexa - 您可以在不经过意图的情况下将(状态)信息发布到 Alexa Skill 吗?
- c - 需要一个像 read() 这样的函数,它将整数数据读入缓冲区并获得与 read() 相同的缓冲区值
- javascript - 用于根据 HTML 文本框中的值输入日期的 JavaScript
- python - 如何获得关联对象的反向引用 - 即 user.follows() 和 user.followers()
- ios - Ionic iOS 13.2 错误,应用程序崩溃 - kill() 返回意外错误
- javascript - 无效语法未标记为(或未标记)?
- javascript - 用JS分页表时,Firebase数据库中的数据没有出现
- c# - 如何阻止newtonsoft json进行驼峰式处理
- java - 依赖注入的 Java 模块化