question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support setting Context displayName in `@babel/plugin-transform-react-display-name`

See original GitHub issue

Feature Request

  • I would like to work on this feature!
  • I have bandwidth to work on this feature in the near future. 🙁

Is your feature request related to a problem? Please describe.

Here’s an example of React DevTools with a few context providers and consumers:

image

You’ll notice that the context consumer and provider rendered under ThemeProvider have generic Context.Consumer and Context.Provider display names, but there’s also a Router.Provider and Router.Consumer in there which are much more clear.

They accomplish this by setting the context’s displayName value.

Here are some test cases:

import React from 'react'

const MyContext = React.createContext()
MyContext.displayName = 'MyContext'

Describe the solution you’d like

I’d like @babel/plugin-transform-react-display-name to support automatically setting the displayName property for contexts.

Describe alternatives you’ve considered

I can set it manually. Not desirable. Or I could write my own babel plugin, but then others wouldn’t benefit from it if they either don’t know about the plugin or can’t install it. Also, this seems to make a lot of sense to be included here to me.

Teachability, Documentation, Adoption, Migration Strategy

No need, it’ll just magically start working and people will be pleasantly surprised.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:44
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
existentialismcommented, Mar 11, 2020
2reactions
nicolo-ribaudocommented, Mar 11, 2020

Oh wow, I had no idea that our plugin was so outdated.

@roncohen Would you be open to adding this feature to babel-plugin-add-react-displayname, and then merging babel-plugin-add-react-displayname to the official Babel plugin?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Support setting Context displayName in `@babel ...
Support setting Context displayName in `@babel/plugin-transform-react-display-name `
Read more >
@babel/plugin-transform-react-display-name | Yarn - Yarn
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >
babel/plugin-transform-react-display-name
Out var foo = React.createClass({ displayName: "foo", }); // React <= 15 var bar = createReactClass({ displayName: "bar", }); // React 16+.
Read more >
Context - React
Context provides a way to pass data through the component tree without having to pass props down ... Context object accepts a displayName...
Read more >
babel/plugin-syntax-top-level-await - NPM Package Overview
... #13396 Add support for d flag of regex literals in parser (@ota-meshi). babel-helpers ... babel-plugin-transform-react-display-name ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found