12 React Websocket. Problems with useEffect with arrays and concatenated strings
1. Explanation of this example In this example, the process is the following: the client (React) sends a request to the server. The server receives the request and while processing, it sends messages informing the client about the process The last message sent to the client is "close-me", which means that the server has finished its work When the client receives any message, this message is stored both in a string and in an array When the client receives the message "close-me", then it closes the connection. 2. Problems with variables 1. Inside the " useEffect ", the variables in an assignment must be all in " useState ." As inside a " useEffect " code, the variables that don't use " useState " are initialized. 2. Don't use " useEffect " for detecting changes in arrays or strings whose value is concatenated ( for instance setMyVar(myVar + aString) ) 3. Taking care of non-open connections If you want to send...