memo
This commit is contained in:
cv
2021-05-10 22:55:23 +02:00
parent 1c3ec66342
commit bd677163ed
3 changed files with 80 additions and 73 deletions
@@ -1,19 +1,15 @@
import { memo, useEffect, useState } from 'react';
import { memo } from 'react';
import { formatDisplay } from '../../dateConfig';
import styles from './Countdown.module.css';
const Countdown = ({ time, small, negative, hideZeroHours }) => {
const [clock, setClock] = useState(time);
let display = '-- : -- : --';
useEffect(() => {
setClock(time);
}, [time]);
// prepare display string
if (clock != null && !isNaN(clock))
display = formatDisplay(Math.abs(clock), hideZeroHours);
if (time != null && !isNaN(time))
display = formatDisplay(Math.abs(time), hideZeroHours);
const colour = negative ? '#ff7597' : '#fffffa';
return (
<div
className={small ? styles.countdownClockSmall : styles.countdownClock}