Is this possible to do
I'm relatively new with react. Recently I started working with websockets. I've built a websocket and it got rather large, in order to help keep things organized I decided to create a single object in a separate file with the websocket functionality. So the new object has a function for opening the socket and handling all the interactions with the back end and I passed to it a number of functions for updating my variables.
One of my variables is another objection with functions and variables. Not all the variables get updated with each call to the backend so my code looks like this:
const [tableInfo, setTableInfo]=useState(tableInfoDefaultObject);
...
const UpdateTableInfo = (dictionaryForUpdate)=>{
setTableInfo({...tableInfo, ...dictionaryForUpdate})
and I pass the UpdateTableInfo function to the websocket object. What I'm finding is that it only uses the original default tableInfo. I think it passes the whole function instead of just a reference to it but I'm still a bit foggy on how react does this. Is there a way around this? I'm OK with moving the functionality back into the main web page, just wanted to organize things better and figured that there's probably a way to make this happen.