I'm creating an app that reads the alarm state of several ELK alarm systems. I'm using useState to process the data that I am receiving via socket.io from my server. The data that the server is streaming is an array of arrays.
This is the code that I am using:
const [startData, updateData] = React.useState([]);
const socket = io("http://localhost:5000");
socket.on('data', (dta) => {
updateData(dta.data);
});
If I console.log(startData) then it becomes evident that my code is causing an infinite loop. I read through examples of users in this forum with similar issues but I wasn't successful in tailoring their solutions to my problem. I was somewhat able to manage the amount of requests with setTimeout but after the app is running for about 2 hours, the page becomes unresponsive (memory leak????).
Do you people have any suggestion on how I could improve my code?