最佳答案
你可以看看React Test Renderer .
provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.
然后为你的树创建一个 JSON 重新表示
const instance = TestRenderer.create(<MyComponent />);
instance.toJSON();
关于javascript - 如何获得一个 react 组件树,就像它在 react 开发工具中显示的那样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51943011/