I have such a problem:
I have an array of data, and I have an array of time. These are the arrays:
const Reps = {
TimeOfMove: [1, 2.5, 3, 3.5, 4.5, 5, 6, 10, 12, 13, 14, 15.5],
ScoreOfMove: [60, 85, 42, 60, 70, 80, 90, 100, 90, 40, 0, 20],
};
After a second I want to display the number 60, after 2.5 seconds the number 85, and so these ...
Also i want to display the ScoreOfMove array after a second as: [60,0... 0], after 2.5 seconds the array as: [60,85,0...0].
This is the code I've been trying to do so far, but it's not working for me
import React, { useEffect, useState } from 'react';
import "./styles.css";
const Reps = {
TimeOfMove: [1, 2.5, 3, 3.5, 4.5, 5, 6, 10, 12, 13, 14, 15.5],
ScoreOfMove: [60, 85, 42, 60, 70, 80, 90, 100, 90, 40, 0, 20],
};
let i = 0;
export default function App() {
const [time, setTime] = useState('');
const [timeArr, setTimeArr] = useState([]);
useEffect(() => {
setTimeout(() => {
setTime(Reps.ScoreOfMove[i])
i++;
}, Reps.TimeOfMove[i] * 1000)
}, [time])
return (
<div className="App">
{time}
{timeArr}
</div>
);
}
I want to display different text each time,and different array each time, according to the time it appears.