NuxtN
Nuxt2y ago
10 replies
Rush

Pinia store socket.io error

Hi, I want to store my socket.io connection in pinia store. This is my code:

import { io } from 'socket.io-client';

export const useWebsocketStore = defineStore('websocketStore', {
  state: () => ({
    isConnected: false,
    socket: null,
  }),
  actions: {
    init() {
      this.socket = io();
      this.bindEvents();
    },
    bindEvents() {
      if (this.socket) {
        this.socket.on("connect", () => {
          this.isConnected = true;
        });

        this.socket.on("disconnect", () => {
          this.isConnected = false;
        });

        this.socket.on("error", (error) => {
          console.log(error);
        });
      }
    },
  },
});


but I am getting this error:

Cannot stringify arbitrary non-POJOs

what to do please?
Was this page helpful?