函数组件的使用方式

//先定义一个uerRef
const inputRef = useRef(null) as React.MutableRefObject<any>

//通过组件自带的ref给inputRef赋值
<TextInput
    ref={inputRef}
    placeholderTextColor={"#9b9b9b"}
/>

//最后通过inputRef.current调用相关方法

//获得焦点
inputRef.current.focus() 

//设置光标位置,数字代表需要将光标置于文本框中的指定位置
inputRef.current.setNativeProps({selection: { start: 1, end: 1 }})

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐