mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
fix: request timer issue (#3175)
This commit is contained in:
parent
da9f669a2d
commit
6e4d7a6f76
@ -1,25 +1,23 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
const StopWatch = ({ requestTimestamp }) => {
|
||||
const StopWatch = () => {
|
||||
const [milliseconds, setMilliseconds] = useState(0);
|
||||
|
||||
const tickInterval = 200;
|
||||
const tickInterval = 100;
|
||||
const tick = () => {
|
||||
setMilliseconds(milliseconds + tickInterval);
|
||||
setMilliseconds(_milliseconds => _milliseconds + tickInterval);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let timerID = setInterval(() => tick(), tickInterval);
|
||||
let timerID = setInterval(() => {
|
||||
tick()
|
||||
}, tickInterval);
|
||||
return () => {
|
||||
clearInterval(timerID);
|
||||
clearTimeout(timerID);
|
||||
};
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setMilliseconds(Date.now() - requestTimestamp);
|
||||
}, [requestTimestamp]);
|
||||
|
||||
if (milliseconds < 1000) {
|
||||
if (milliseconds < 250) {
|
||||
return 'Loading...';
|
||||
}
|
||||
|
||||
@ -27,4 +25,4 @@ const StopWatch = ({ requestTimestamp }) => {
|
||||
return <span>{seconds.toFixed(1)}s</span>;
|
||||
};
|
||||
|
||||
export default StopWatch;
|
||||
export default React.memo(StopWatch);
|
||||
|
Loading…
Reference in New Issue
Block a user