我想在超时时使用 ref 清除文本组件,但找不到。
<Text style={{ color: "#fff" }} ref={text => this._text = text}>
{isKeyValid === undefined
? null
: isKeyValid
? "Key is been verified."
: "Your key is invalid or expired."}
</Text>
clearErrorMessages = () => {
setTimeout(() => {
//something like that here which i have no idea
this._text.clear()
}, 2000);
}
关于这些人的任何想法谢谢...
最佳答案
没有方法可以清除 <Text>
中的文本成分。
您可以这样做:获取您想要在状态变量中显示的任何值,并在需要时将其设置为空字符串。
在构造函数中:
this.state={
value:"myvalue",
}
渲染中
<Text>{this.state.value}</Text>
然后在您想要清除文本的任何操作/功能上执行此操作:
this.setState({value:""});
关于javascript - 如何在 React Native 中使用 ref 清除文本组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55513708/