You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I was wondering how you can change a state inside the onMessage callback, since by default it's using a wrong reference of whatever state you place inside it.
Do you know any workaround for that?
I've changed up your example a bit, did it break something, that I'm not aware of?
constonMessage=useCallback((event: MessageEvent)=>{setMessage(event.data);// This doesn't work/updates the real stateconsole.log("Message from server ",event.data);},[]);useEffect(()=>{ws?.addEventListener("message",onMessage);return()=>ws?.removeEventListener("message",onMessage);},[onMessage,ws]);
The text was updated successfully, but these errors were encountered:
Hello, I was wondering how you can change a state inside the onMessage callback, since by default it's using a wrong reference of whatever state you place inside it.
Do you know any workaround for that?
I've changed up your example a bit, did it break something, that I'm not aware of?
The text was updated successfully, but these errors were encountered: