Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it Possible to Rename Recompose HOC (For Better Stack Traces)?

I love recompose, but when I use it I wind up with stack traces that have lines like:

in withProps(withHandlers(withHandlers(SelectionOverlay))) (created by withState(withProps(withHandlers(withHandlers(SelectionOverlay)))))

Is there any way I can give some sort of "display name" to the individual HOC components to get more readable stack traces?

like image 556
machineghost Avatar asked Dec 19 '25 07:12

machineghost


2 Answers

There is a setDisplayName method available that seems to do what you are asking - https://github.com/acdlite/recompose/blob/master/docs/API.md#setdisplayname

like image 168
Hugo Silva Avatar answered Dec 21 '25 23:12

Hugo Silva


Checkout this section: https://github.com/acdlite/recompose#build-your-own-libraries

I believe you can just assign a static property to your component called displayName and that will be passed through to stack traces as well as the React chrome extension.

So if your HOC is composed like this, you can just write:

const MyComponent = withProps(withHandlers(withHandlers(SelectionOverlay)))

MyComponent.displayName = "ArbitraryValue"
like image 26
Jon Jaques Avatar answered Dec 21 '25 21:12

Jon Jaques



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!