简体   繁体   English

一种跟踪页面中调用的所有组件的方法

[英]a way to track all the components that are called in a page

I need a way to track all the component calls when a page renders, for example if my page is like:我需要一种方法来跟踪页面呈现时的所有组件调用,例如,如果我的页面如下:

<MyPage>
   <A />
   <B>
      <B2/>
      <B3>
   </B>
   <C /> // witch the component C, calls D in its own code
</MyPage>

and C is like:和 C 就像:

<C>
   <D />
</C>

something like that, witch a bunch of nested components are called for a page to be rendered, I need a list of all of them, in this example, I need (A, B, B2, B3, C, D),类似的东西,需要一堆嵌套组件来渲染页面,我需要所有这些的列表,在这个例子中,我需要(A,B,B2,B3,C,D),

is this possible?这可能吗?

Have you taken a look at the React Developer Tools addon ( Chrome , Firefox )?你看过 React Developer Tools 插件( ChromeFirefox )吗? That will add a "Components" tab to your developer tools, which looks like this:这将为您的开发人员工具添加一个“组件”选项卡,如下所示:

React 开发者工具截图

You can then select any component to get more details about it as well.然后,您可以 select 任何组件以获取有关它的更多详细信息。

It's like you asking something already done in React Chrome extension,which is an open source project.. When you looked into its main.js file https://github.com/facebook/react/blob/master/packages/react-devtools-extensions/src/main.js Which got some noticable imports就像你在问一些已经在 React Chrome 扩展中完成的事情,这是一个开源项目。当你查看它的 main.js 文件https://github.com/facebook/react/blob/master/packages/react-devtools -extensions/src/main.js其中有一些值得注意的导入

import { getAppendComponentStack, getBreakOnConsoleErrors, getSavedComponentFilters, getShowInlineWarningsAndErrors, } from 'react-devtools-shared/src/utils';导入 { getAppendComponentStack, getBreakOnConsoleErrors, getSavedComponentFilters, getShowInlineWarningsAndErrors, } from 'react-devtools-shared/src/utils';

I think what you need is must be inside getAppendComponentStack Utility.. Check also this https://github.com/facebook/react/blob/master/packages/react-devtools-shared/src/utils.js我认为你需要的是必须在 getAppendComponentStack 实用程序中.. 还要检查这个https://github.com/facebook/react/blob/master/packages/react-devtools-shared/src/utils.js

Sure you will workout a solution with some analysis..当然,您将通过一些分析来锻炼解决方案..

#using Mobile edition.. Please bear with the format of the answer. #使用手机版..请以答案格式为准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM