【发布时间】:2020-02-27 08:52:07
【问题描述】:
当 recordUpdateSuccess 的布尔值变为 true 并且 3 秒后它应该消失时,我想在成功更新记录后显示一条自定义消息。
{recordUpdateSuccess ? this.renderRecordUpdatedSucess() : null}
我有显示消息的功能:
renderRecordUpdatedSucess = () => (
<View style={styles.sucessAlert}>
<Text style={styles.sucessAlert}>Record updated successfully.</Text>
</View>
)
我尝试使用 setTimeout() 来显示消息但不起作用。 任何实现这一目标的想法。 我不想使用 Toast,任何第三方库都可以。
【问题讨论】:
-
显示完整组件,你确定 recordUpdateSuccess 是真的吗?
-
请添加完整代码!
-
@Borjante Yes recordUpdateSuccess true 并显示消息,但我想在几秒钟后将其消失,所以我输入 setTimeout(()=>{ this.setState({recordUpdateSuccess: false}) },3000)
-
完整代码请@RaviSharma
标签: react-native settimeout flash-message