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

Allow to specify displayName for createContext() providers and consumers #12695

Closed
budarin opened this issue Apr 26, 2018 · 5 comments
Closed

Comments

@budarin
Copy link

budarin commented Apr 26, 2018

Do you want to request a feature or report a bug?
bug

What is the current behavior?
in React tree name of a Context must be like its name in code

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

const MyContext = React.createContext(null);
   <MyContext.Consumer>
   { data => ... }
   </MyContext.Consumer>

let's have a look at React tree in Chrome extention's page

here is Context - not MyContext

What is the expected behavior?

expexted to see MyContext

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

16.3.2

@gaearon
Copy link
Collaborator

gaearon commented Apr 26, 2018

React can't "guess" the name from the declaring code but we should probably make it possible to specify displayName manually for React DevTools.

@gaearon gaearon changed the title Set correct displayNmae to Context Allow to specify displayName for createContext() providers and consumers Apr 26, 2018
@budarin
Copy link
Author

budarin commented Apr 26, 2018

Thanks 😃

@kaushik94
Copy link

@gaearon can I take this up?

@devmonkey22
Copy link

I think this is the paired React DevTools issue (facebook/react-devtools#1008)

@bvaughn
Copy link
Contributor

bvaughn commented Jan 23, 2019

Context providers and consumers support a custom display in React DevTools like so:

const ThemeContext = React.createContext("light");
ThemeContext.displayName = 'ThemeContext';

<ThemeContext.Provider> // "ThemeContext.Provider" in DevTools
<ThemeContext.Consumer> // "ThemeContext.Consumer" in DevTools

@bvaughn bvaughn closed this as completed Jan 23, 2019
facebook-github-bot pushed a commit to facebook/flow that referenced this issue Jan 26, 2019
Summary:
Related: facebook/react#12695 (comment)

Context providers and consumers [support a custom display in React DevTools](https://github.com/facebook/react-devtools/blob/38fe9782f82fbcb4f6137e5b920147d35ebe1992/backend/attachRendererFiber.js#L362-L387) like so:

```js
const ThemeContext = React.createContext("light");
ThemeContext.displayName = 'ThemeContext';

<ThemeContext.Provider> // "ThemeContext.Provider" in DevTools
<ThemeContext.Consumer> // "ThemeContext.Consumer" in DevTools
```

cc jbrown215
Pull Request resolved: #7387

Reviewed By: bvaughn

Differential Revision: D13792923

Pulled By: jbrown215

fbshipit-source-id: 28e9b51e1e740b5f7cad78edc5f056779a9ec8b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants