我正在尝试存储和检索 socket.io session ,但 React 抛出一个错误,指出它无法保存循环对象。
我试图将对象字符串化,但没有成功。有没有不进入 Redux 的解决方法?
商店:
localStorage.setItem('socket', JSON.stringify(socket));
检索:
const socket = localStorage.getItem("socket");
尝试字符串化对象返回:
Uncaught TypeError: Converting circular structure to JSON
at Object.stringify (<anonymous>)
at <anonymous>:1:7
最佳答案
您可以使用检查方法 你可以立即导入它,因为它来自节点
const util = require('util')
然后检查对象并记录
关于javascript - 圆形对象的本地存储(socket.io),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54630899/