如何将 Mobx 可观察对象转换为字符串

Bha*_*ade 2 history reactjs react-router mobx mobx-react

我正在使用 Mobx 来创建可观察状态。

这是我的代码片段:

window.sessionStorage.setItem(createKey(key), JSON.stringify(state))
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,“状态”对象是可观察的。当我尝试将其转换为字符串时,出现错误:

错误:无法读取未定义的属性“atom”

mwe*_*ate 5

使用JSON.stringify(mobx.toJS(state))