CountDown .js 654 B

1234567891011121314151617181920212223
  1. import * as React from 'react';
  2. import { useThrottleFn } from '@umijs/hooks';
  3. import { Text } from 'react-native-magnus';
  4. import Time from '../Utils/TimeUtils';
  5. export default function CountDown(props) {
  6. const { endTime, format, size, color, valueFormat } = props;
  7. const [value, setValue] = React.useState(
  8. new Time(endTime, format).getNowTime(valueFormat)
  9. );
  10. const { run } = useThrottleFn(() => {
  11. setValue(new Time(endTime, format).getNowTime(valueFormat));
  12. setTimeout(() => {
  13. run();
  14. }, 500);
  15. }, 1000);
  16. run();
  17. return (
  18. <Text fontSize={size} color={color}>
  19. {value}
  20. </Text>
  21. );
  22. }