All Questions
68
questions
-1
votes
1
answer
52
views
React State Resets to Default When WebSocket Message is Received
I'm working on a React project using WebSockets to receive real-time updates. However, I'm encountering an issue where my component's state resets to the default value every time a WebSocket message ...
0
votes
0
answers
48
views
React Native Expo , the intialized custom socket connection shows error:
I want a help and it would be very grateful if anyone would help me to debug the code and tell me whats am I doing wrong here: my custom websocket hook
the error I get is that, it prints out the ...
0
votes
1
answer
68
views
Socket connection does not disconnect at useEffect cleanup function
I have this code :
useEffect(() => {
const init = async () => {
try {
socketRef.current = await initSocket();
socketRef.current.on("connect_error", (err) =&...
0
votes
0
answers
269
views
Receiving Duplicate Messages from WebSocket Server in React Component
Problem Description:
I'm currently working on a project where I'm using a WebSocket server to send real-time updates to a React component. However, I'm encountering a problem where the same message is ...
0
votes
0
answers
102
views
Using react-use-websocket inside of a Web Worker (Comlink)
I have a websocket that sends and receives data and I want it to be running in a different thread. The thing is, I'm using react-use-websocket which is a react custom hook and I need to run that in a ...
0
votes
1
answer
301
views
useEffect getting called multiple times in React without Strict mode
I want to run the connect function only once so that it initiates a stompjs client. But it is being called 4 times and I am getting the following message in the browser:
VM1867 bundle.js:41684 ...
0
votes
0
answers
232
views
What is the proper way to clean up STOMP client in React useEffect?
I'm using Strict mode so double rendering is causing there to be two socket connections opened by the following useEffect:
useEffect(() => {
const socket = new SockJS(url);
const clientObj=...
0
votes
1
answer
212
views
React native websocket working in debug mode but not after creating apk
Please help. I am creating an app in react native that displays live data of orders, everything is working fine in debug mode when I run the app on the emulator or directly run it on my mobile, the ...
2
votes
3
answers
208
views
React Invalid hook call: how to avoid a nested hook?
How can I set up a connection inside useEffect and at the same time decorate that connection with a custom hook? Custom hooks are not allowed to run inside useEffect and ref.current is not permitted ...
2
votes
3
answers
188
views
In React, why is my array thought to be empty in a function triggered by a websocket message?
In React I have an array variable defined using useState, called messages. I also have a component on the page which doesn't have any DOM but rather listens for events on a websocket. When my ...
0
votes
1
answer
45
views
React not rendering long list of strings
I have a long array in React, over 600 items of strings. I have a map function that lists these strings in a log. When I update the empty list to add all the strings, the update is fairly immediate ...
0
votes
0
answers
125
views
Websocket in React not rendering component when state is changed
I'm developing a ChatGPT client backend/frontend. Backend is sending via websockets a streaming response writing text asynchronously.
But it seems frontend is not rendering components until whole ...
0
votes
0
answers
358
views
Why sending json message in webSocket caused a lot re-render in react app
I have a form that want to send message via webSocket when click on submit button but after click and send message my component repeats in a cycle and my console shows a lot of console.log; I tried ...
1
vote
1
answer
149
views
How to connect to Websocket server with a config that comes from an api?
I'm trying to connect to a websocket server in react but I have to get the connection config from an api. I can't find the right pattern to do that.
I need to:
Get the config from the api using react-...
0
votes
1
answer
49
views
Understanding behavior of clousers and event listeners in React component with WebSocket call
I have the following component:
function SocketClient() {
const [socket, setSocket]= React.useState(null);
const [msg, setMsg] = React.useState([]);
function handleMessage(event) {
setMsg([.....