【发布时间】:2021-09-16 14:57:00
【问题描述】:
在 react native 中执行 navigate.goBack() 后,我尝试专注于输入字段。
我看到了一些使用 Ref 的解决方案。我试过了,但这种类型的解决方案仍然不适合我?
import React, { useState, useEffect, useRef } from 'react';
const textInput = useRef();
useEffect(() => {
const unsubscribe = navigation.addListener('focus', () => {
textInput.current.focus();
loadData()
});
return unsubscribe;
}, [navigation]);
<TextInput
ref={textInput}
value={text}
placeholder="Your name"
style={styles.textInput} />
如何在 React Native 中做到这一点? 我已经在谷歌和这个网站上搜索过它。但是所有的解决方案都不适合我。
谢谢!
【问题讨论】: