Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add displayName property to context object for easier debugging with React Devtools #30

Merged
merged 2 commits into from
Feb 5, 2020

Conversation

Dman757
Copy link
Contributor

@Dman757 Dman757 commented Feb 4, 2020

Summary & motivation

Simple change to make debugging with React DevTools a little bit easier by having a non-generic displayName.

In the devtools window the context component currently shows up as <Context.Provdier> this change would make it show up as <Stripe.Provider> With the generic name it can be a little annoying debugging if you have multiple providers all with the same generic displayName.

before
Screen Shot 2020-02-04 at 10 02 10 AM
after
Screen Shot 2020-02-04 at 10 00 58 AM

If you're unfamiliar with the context displayName documentation is here: https://reactjs.org/docs/context.html#contextdisplayname

My real motivation for this is an issue with a project that has multiple generic named "Provider" components and I was tracking the following a warning down:
Screen Shot 2020-02-04 at 10 15 56 AM
After a little bit of digging realized it was related to react-stripe-elements as it has a context provider just named <Provider> So I just want to make this new iteration of stripe elements a little bit easier to debug.

Testing & documentation

Use React DevTools to confirm that the correct displayName is present.

Note for maintainers I chose a generic displayName "Stripe" but will leave it up to you if you want a more descriptive name like StripeContext or StripeElementContext

@Dman757 Dman757 marked this pull request as ready for review February 4, 2020 18:26
@Dman757 Dman757 changed the title Add displayName property to context object Add displayName property to context object for easier debugging with React Devtools Feb 4, 2020
Copy link
Contributor

@christopher-stripe christopher-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dman757 Thanks! Left a small suggestion for the name but lgtm.

src/components/Elements.js Outdated Show resolved Hide resolved
maintainer suggested context name

Co-Authored-By: Christopher Henn <[email protected]>
@Dman757
Copy link
Contributor Author

Dman757 commented Feb 5, 2020

Pushed change to naming "Stripe" => "ElementsContext" per @christopher-stripe suggestion. Will show up in React Devtools as ElementsContext.Provider now. Thanks for the review!

@christopher-stripe christopher-stripe merged commit b646da0 into stripe:master Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants