lahsivjar / react-stomp

React websocket component for STOMP protocol over SockJs
https://www.npmjs.com/package/react-stomp
MIT License
134 stars 41 forks source link

TypeError: Cannot read property 'sendMessage' of undefined. Send to/with different topics/msg #175

Open cazherosu opened 3 years ago

cazherosu commented 3 years ago

Might be a dumb question, but how do you send messages with different topic and/or msg. I tried doing it in a switch-case, but that resulted in this error.

sendMessage = (messageMap) => { switch (messageMap) { case this.wsGet: this.clientRef.send(this.destinationPrefix + this.wsGet + "/" + this.roomId); break; case this.wsPost: this.clientRef.send(this.destinationPrefix + this.wsPost + "/" + this.roomId, {}, JSON.stringify({ taskName: this.state.taskName, taskDescription: this.state.taskDescription, finished: false })) break; default: console.log("sendMessage case was default...yikes"); break; } };