In setInterval, I’m trying to add constantly changing data to the useState hook, but it always shows the first value.
I don’t want to use spread operator or prev constructs (it works with these), because the data will be updated every 1 second. Since these structures constantly copy data to memory, memory usage constantly increases.
Is there any other method to update the useState value continuously.
example code;
const [getData, setData] = useState(data);
const exData = [] // Constantly Updating
useEffect(() => {
const interval = setInterval(() => {
setData(exData);
}, 1000);
return () => clearInterval(interval);
}, []);
useEffect(() => {
console.log(getData);
}, [getData]);