fix for bad network requests before component ready

This commit is contained in:
Michael Quigley 2023-05-17 11:45:48 -04:00
parent bdf1a32d6a
commit 1aaba521c7
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -9,6 +9,7 @@ const MetricsTab = (props) => {
const [metrics1, setMetrics1] = useState(buildMetrics([]));
useEffect(() => {
if(props.share.token) {
metadata.getShareMetrics(props.share.token)
.then(resp => {
setMetrics30(buildMetrics(resp.data));
@ -21,11 +22,13 @@ const MetricsTab = (props) => {
.then(resp => {
setMetrics1(buildMetrics(resp.data));
});
}
}, [props.share]);
useEffect(() => {
let mounted = true;
let interval = setInterval(() => {
if(props.share.token) {
metadata.getShareMetrics(props.share.token)
.then(resp => {
if(mounted) {
@ -34,12 +37,17 @@ const MetricsTab = (props) => {
});
metadata.getShareMetrics(props.share.token, {duration: "168h"})
.then(resp => {
if(mounted) {
setMetrics7(buildMetrics(resp.data));
}
});
metadata.getShareMetrics(props.share.token, {duration: "24h"})
.then(resp => {
if(mounted) {
setMetrics1(buildMetrics(resp.data));
}
});
}
}, 5000);
return () => {
mounted = false;