简体   繁体   中英

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.

conclusion is get react component Name inside componentDidCatch in producation build.

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

and I also saw some webpack related things (production config's uglify) but it's not proper clear.

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:

this._reactInternalFiber.elementType.name 

Note that it might be instable due to using a private property that belongs to React.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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