2

I'm trying to store and retrieve a socket.io session but react is throwing an error saying that it can't save a circular object.

I've tried to stringify the object but no luck. Any work around without going into Redux?

Store:

localStorage.setItem('socket', JSON.stringify(socket));

Retrieve:

const socket = localStorage.getItem("socket");

Attempting to stringify the object returns:

Uncaught TypeError: Converting circular structure to JSON at Object.stringify (<anonymous>) at <anonymous>:1:7

Stephanie Parker
  • 371
  • 3
  • 17

1 Answers1

1

You can use the inspect method you can import it immediately since it's from node with

const util = require('util')

And then inspect the object and log that

Aron
  • 38
  • 5