React setState not updating state inside stompjs callback function
neerajjain92 opened this issue · 3 comments
neerajjain92 commented
const [stompClientRef, setStompClientRef] = useState(false); // ------> This is the state
const onConnected = () => {
console.log(
"Connected to backend StompEndpoint...!! ",
WEB_SOCKET_BACKEND_URL
);
stompClient.subscribe(
"/topic/live-tracking/1-neeraj/2-admin",
handleOnMessageReceived,
{ id: "live-tracking-ws-topic-id" }
);
};
const handleOnMessageReceived = (msg: any) => {
console.log("StompClient..........", stompClient);
setStompClientRef(true);
console.log("stompClientRef.......", stompClientRef);
const tripGeoCoordinate = JSON.parse(msg.body);
console.log(tripGeoCoordinate);
};
Even when handleOnMessageReceived is invoked, setState isn't working.... stompClientRef is always false.
Harsha988 commented
same here the initial state itself is sustained by the states inside the callback function. when ever I tried to log them. If anyone could resolve this problem it would be nice.
auvipy commented
I would love to have a PR with failing test first
github-actions commented
This issue has been inactive for 30 days. It will be in closed in 5 days without any new activity.