mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 01:14:23 +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';
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
const StopWatch = ({ requestTimestamp }) => {
|
const StopWatch = () => {
|
||||||
const [milliseconds, setMilliseconds] = useState(0);
|
const [milliseconds, setMilliseconds] = useState(0);
|
||||||
|
|
||||||
const tickInterval = 200;
|
const tickInterval = 100;
|
||||||
const tick = () => {
|
const tick = () => {
|
||||||
setMilliseconds(milliseconds + tickInterval);
|
setMilliseconds(_milliseconds => _milliseconds + tickInterval);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let timerID = setInterval(() => tick(), tickInterval);
|
let timerID = setInterval(() => {
|
||||||
|
tick()
|
||||||
|
}, tickInterval);
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(timerID);
|
clearTimeout(timerID);
|
||||||
};
|
};
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
if (milliseconds < 250) {
|
||||||
setMilliseconds(Date.now() - requestTimestamp);
|
|
||||||
}, [requestTimestamp]);
|
|
||||||
|
|
||||||
if (milliseconds < 1000) {
|
|
||||||
return 'Loading...';
|
return 'Loading...';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,4 +25,4 @@ const StopWatch = ({ requestTimestamp }) => {
|
|||||||
return <span>{seconds.toFixed(1)}s</span>;
|
return <span>{seconds.toFixed(1)}s</span>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default StopWatch;
|
export default React.memo(StopWatch);
|
||||||
|
Loading…
Reference in New Issue
Block a user