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

displayName not supported in combination with forwardRef in "React Developer Tools" #13703

Closed
mcjazzyfunky opened this issue Sep 20, 2018 · 3 comments

Comments

@mcjazzyfunky
Copy link

mcjazzyfunky commented Sep 20, 2018

The display names of components that are based on React.forwardRef are currently ignored in "React Developer Tools" (=> name is always "ForwardRef" ).
I think this is a bug.

Example:

Edit:
https://jsbin.com/nutetosaxu/edit?html,js,output

Preview:
https://jsbin.com/nutetosaxu

@mcjazzyfunky mcjazzyfunky changed the title displayName not supported in combination with forwardRef displayName not supported in combination with forwardRef in "React Developer Tools" Sep 20, 2018
@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2018

Check out the docs:
https://reactjs.org/docs/forwarding-refs.html#displaying-a-custom-name-in-devtools

The function you pass to React.forwardRef needs to be named, rather than the object returned by React.forwardRef:

const MyComponent = React.forwardRef(function nameThisThing(props, ref) {
  return "[MyComponent]";
});

Updated code: https://codesandbox.io/s/oqy4q045qy
Preview: https://oqy4q045qy.codesandbox.io/

@bvaughn bvaughn closed this as completed Sep 20, 2018
@mcjazzyfunky
Copy link
Author

Oooops, like always: It helps if you can read ;-)
Thanks a lot @bvaughn - I've overlooked that part in the documentation :-(

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2018

No worries. Looks like an easy mistake to make!

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

No branches or pull requests

2 participants