简体   繁体   English

如何在生产构建中获取 componentDidCatch 中的反应组件名称?

[英]How to get react component Name inside componentDidCatch in producation build?

I used error boundary inside (componentDidCatch)I want to log which react component is break in producation build.我在(componentDidCatch)内部使用了错误边界我想记录哪个反应组件在生产构建中中断。

conclusion is get react component Name inside componentDidCatch in producation build.结论是在生产构建中的 componentDidCatch 中获取反应组件名称。

I read many article and below link this is same as I asked in question but it's not solve my problem.我阅读了很多文章,下面的链接与我提出的问题相同,但这并不能解决我的问题。 Getting React Component by name 按名称获取 React 组件

and I also saw some webpack related things (production config's uglify) but it's not proper clear.而且我还看到了一些 webpack 相关的东西(生产配置的丑陋),但还不清楚。

let me know if any simplest way to solve this issue让我知道是否有任何最简单的方法可以解决此问题

By design, you should never be able to see debugging information in a production build.按照设计,您永远无法在生产构建中看到调试信息。 What you are trying to accomplish here is an anti-pattern.您在这里尝试完成的是反模式。 However, if you still want to go through with it, you can use:但是,如果您仍然希望 go 通过它,您可以使用:

this._reactInternalFiber.elementType.name 

Note that it might be instable due to using a private property that belongs to React.请注意,由于使用了属于 React 的私有属性,它可能会不稳定。

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

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