react-native - 有人可以帮助我,以便当我单击按钮时,计时器会重置吗?谢谢
问题描述
import React from 'react';
import { Text, View, StyleSheet, FlatList, TextInput, Button,KeyboardAvoidingView, Keyboard } from 'react-native';
import CountDown from 'react-native-countdown-component';
const App=()=> {
return (
<View>
<CountDown
until={10}
onFinish={() => alert('hello')}
onPress={() => alert('hello')}
size={20}
/>
<Button title = "reset timer"
>
</Button>
</View>
)
}
export default App;
解决方案
在状态和按下按钮时设置默认值复位状态
尝试这个
import React, { useState } from 'react';
const App=()=> {
const [count, setCount] = useState(10);
return (
<View>
<CountDown
until={count}
onFinish={() => alert('hello')}
onPress={() => alert('hello')}
size={20}
/>
<Button title = "reset timer"
onPress={() => setCount(10)}
>
</Button>
</View>
)
}
export default App;
推荐阅读
- php - 如何检查用户是否存在pricing_plan_id?
- node.js - PM2 崩溃后自动重启
- javascript - 根据它的旋转将 div 从卡扇向外移动?
- chatbase - Chatbase 返回 200,但概览为空
- javascript - 按钮点击,一切都消失了
- qt - Qt:用另一个模型扩展 QFileSystemModel
- java - 放心:发布请求返回错误“JSON 输入文本不应为空或空”。
- html - 圆形进度条中的圆形图像 [CANVAS]
- ios - Firebase 不会报告 iOS 中的所有崩溃,而 Xcode 10 会报告所有崩溃,我们能否以某种方式跟踪 firebase 上的所有这些崩溃?
- android - Android RTL:阿拉伯语和希伯来语语言支持之间的差异