I'm building an app with a chat right now using Socket.IO and I have a counter of how many users are connected
My problem is that when only one user is connected, the counter shows 3. Why 3 ? Because I have 3 components and I'm importing socket.io-client in each of those like that
import io from "socket.io-client";
const socket = io();
export default {
// bla bla bla
}
How can I import it once and make it available everywhere in my app ? I tried to import it in main.js then using it like
import { io } from 'socket.io-client';
createApp(App)
.use(io)
.mount("#app");
But in my components when I do const socket = io()
it's considered not defined