[英]React native set state to true for one second
I have a state:我有一个状态:
state = {
showView: false,
}
How can I make a function that when called it changes the showView
state to true
for 1 second then change it back to false?如何创建一个函数,当调用它时将
showView
状态更改为true
1 秒,然后将其更改回 false?
this.setState({
showView: true,
}, () => setTimeout(() => {
this.setState({
showView: false,
})
}, 1000))
This will set the state back to false after briefly (1 second) set it to true, using the React setState callback function.这将在使用 React setState 回调函数短暂(1 秒)将状态设置为 true 后将状态设置回 false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.