首页 > 解决方案 > 有人可以帮助我,以便当我单击按钮时,计时器会重置吗?谢谢

问题描述

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;

标签: react-native

解决方案


在状态和按下按钮时设置默认值复位状态

尝试这个

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;

推荐阅读