const [stroke, setStroke] = useState(0);
const updateStroke = () => {
let timer = setInterval(() => {
if (stroke > 1250) {
setStroke(1256);
clearInterval(timer)
}
console.log(stroke);
setStroke(stroke => stroke + 250);
}, 1000);
};
<svg
className="loadingRing"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
onClick={() => updateStroke()}
>
<circle
r="200"
cx="210"
cy="210"
style={{ strokeDashoffset: stroke }}
/>
</svg>
const updateStroke = () => {
let timer = setInterval(() => {
setStroke(stroke => {
console.log(stroke);
if (stroke > 1250) {
clearInterval(timer);
return 1256;
} else {
return stroke + 250;
}
});
}, 1000);
};