Answer the question
In order to leave comments, you need to log in
How to make a repeating animation?
It is necessary to make a change of style in a block that repeats with a certain interval.
I have an array with objects in which the style is registered. It is necessary to change the style in the block with a certain frequency.
Here's what I got:
import React, { useEffect, useState } from "react";
const Result = ({ properties, time }) => {
const [count, setCount] = useState(0);
useEffect(() => {
let timerId = setTimeout(
() => (count < 2 ? setCount((prev) => ++prev) : setCount(0)), // count всегда меньше 3х
`${time}000`
);
}, [count, time]);
let styles = [];
for (let i = 0; i < properties.length; i++) {
styles.push({
color: `${properties[i].color}`,
});
}
return (
<div>
<div
className="banner"
style={styles[count]}
/>
</div>
);
};
export default Result;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question