gosf
gosf copied to clipboard
Compatibility with JavaScript frameworks
I was wondering if this socket.io library was compatible with JavaScript frameworks like React, Vue or Svelte, because JavaScript code written in an HTML file works perfectly fine, but applying the same code to a basic React or Svelte frontend doesn't yield the same results. The connection is made successfully, but messages are not coming through.
First, you need to use npm i socket.io
in your blank Vue/React/Svelte since you are not using cdn links but the npm package. Socket.io is a basic websocket package with some convenient utility functions for creating rooms and lobbies. Next, you import in your main.ts this socket.io package and provide it to your app. From there, you have Vue/React/Svelte life cycle hooks you can use to send events and receive events.