gpt4 book ai didi

javascript - 如何在 native react 中为按钮设置计时器?

转载 作者:行者123 更新时间:2023-11-30 20:08:58 25 4
gpt4 key购买 nike

我是 react-native 的新手。我只需要显示一个按钮 30 分钟。我在互联网上没有关于计时器的明确解决方案,我们将不胜感激。如何将按钮的计时器设置为仅显示 30 分钟并在它之后隐藏?

最佳答案

您可以使用setTimeout 函数来控制按钮的可见性。

示例代码:

class SomeComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
isButtonVisible: true
};
}

componentDidMount() {
setTimeout(() => {
this.setState({ isButtonVisible: false });
}, 1000 * 60 * 30);
}

render() {
const { isButtonVisible } = this.state;
return (;
<View>
...
{
isButtonVisible && <Button .../>
}
</View>
)
}
}

希望这会有所帮助!

关于javascript - 如何在 native react 中为按钮设置计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52595202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com