我尝试获取 TextInput 的值
使用引用
但它给出了未定义的。这是我的代码:
const inputRef = useRef(null);
<TextInput
ref={inputRef}
value={'test'}
editable={false}
style={styles.InputStyle}
/>
console.log(inputRef.current.value) ---> gives undefined
Run Code Online (Sandbox Code Playgroud)
Kul*_*tel -3
使用函数设置引用,如下所示:
<TextInput ref={(ref) => { this.inputRef= ref; }} />
Run Code Online (Sandbox Code Playgroud)
然后您可以通过以下方式访问参考this.inputRef
| 归档时间: |
|
| 查看次数: |
7646 次 |
| 最近记录: |