Fix React cannot update warning

This commit is contained in:
Utku 2022-08-01 16:43:01 +03:00 committed by GitHub
parent de16a11ea0
commit 79941c654b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,15 +52,17 @@ const useCounter = ({ name, start = 0, end, duration = 2, saveState = true }: Us
duration,
easing: 'easeOutCubic'
});
useEffect(() => {
if (saveState && value == end) {
setLastValue(name, end);
}
}, [value]);
if (start === end) return end;
if (saveState && lastValue && lastValue === end) return end;
if (saveState && value == end) {
setLastValue(name, end);
}
return value;
};