I can't seem to figure this out.
I have a socket.io connection to my node server. When ever I emit a message I want to add it to an array and display that array as a scrollable list in the page.
Also what is a good place to declare this array?
import React from 'react';
import './App.css';
import socket from "./index.js";
import UpdateSocketInfo from './socketinfo';
//import statusInfoArray from "./socketinfo";
function App() {
// where do I declare the array statusInfoArray? If i do it inside App it will be empty always?
socket.on("uploadProgress", data => {
statusInfoArray.push(data)
console.log(data);
});
return (
<div className="App">
<UpdateSocketInfo statusInfoArray={statusInfoArray} />
</div>
);
}
export default App;
my socketinfo module
import React from 'react';
// set up status list, is this a good place to declare the array?
//const statusInfoArray= []
//export default statusInfoArray;
export const UpdateSocketInfo = props => {
const statusInfoArray= props;
const returnList = statusInfoArray.map((item) =>
<li>
<span>
{item}
</span>
</li>
);
return (<ul>{returnList}</ul>)
}