UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

18 lines (17 loc) 774 B
import React, { useEffect, useState } from 'react'; export var CooldownTimer = function (_a) { var cooldownInterval = _a.cooldownInterval, setCooldownRemaining = _a.setCooldownRemaining; var _b = useState(cooldownInterval), seconds = _b[0], setSeconds = _b[1]; useEffect(function () { var countdownInterval = setInterval(function () { if (seconds > 0) { setSeconds(seconds - 1); } else { setCooldownRemaining(0); } }, 1000); return function () { return clearInterval(countdownInterval); }; }); return (React.createElement("div", { className: 'str-chat__message-input-cooldown', "data-testid": 'cooldown-timer' }, seconds === 0 ? null : seconds)); };