首页 > 解决方案 > TypeError:在 React Native 上使用 StorybookJS 将循环结构转换为 JSON

问题描述

每当我在 Storybook Navigator 中导航到新故事时,都会发生这种情况。谢谢!

ExceptionsManager.js:126 Unhandled JS Exception: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'HooksContext'
    |     property 'currentContext' -> object with constructor 'Object'
    --- property 'hooks' closes the circle

我正在使用React Native 0.61.5@storybook/react-native 5.3.9

在此处输入图像描述

标签: react-nativestorybook

解决方案


我正在处理同样的问题,不幸的是没有足够的 Storybook 或 React Native 经验来诊断。

但是,我能够按照https://github.com/storybookjs/storybook/issues/9294中的描述修补模块,即“hooks.currentContext = Object.assign({}, context, { hooks: null }); "

重申一下,这不是一个完美的解决方案,因为原始错误来自 currentContext 和钩子之间的嵌套循环关系。这只是将钩子设置为 null 以终止循环结构。


推荐阅读