react-generate-context icon indicating copy to clipboard operation
react-generate-context copied to clipboard

Add `displayName` option for Provider

Open kyleshevlin opened this issue 4 years ago • 1 comments

Because the Provider is created inside the closure of generateContext, it's generically named Provider. So even though you give it a variable name when you destructure it, it still shows up as Provider in your React dev tools. Adding an option for displayName would make this a bit better.

I believe this can be achieved by:

  • [ ] adding providerDisplayName as an option
  • [ ] Default it to undefined or null, just a falsy value that makes sense
  • [ ] if (providerDisplayName) Provider.displayName = providerDisplayName
  • [ ] Updating docs

kyleshevlin avatar Oct 26 '21 18:10 kyleshevlin

It should be noted, that one can add a display name very simply on their own if they need it, this would just be a convenience to the user. They are, of course, welcome to do:

const [MyProvider, useMyContext] = generateContext(useManageValue)
MyProvider.displayName = 'MyProvider'

kyleshevlin avatar Oct 28 '21 06:10 kyleshevlin