-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Component name as prop #15214
Comments
I think let's just keep default behavior, but allow overriding the |
You don't "have to" do it. The question you referenced is about production builds. If you just need it in development, it's enough to give names to your functions. const Foo = () => ...
export default Foo or export default function Foo() {
// ...
} The only reason you have this problem is because you do |
FWIW I disagree with the stance "that's the way it should be". We have such advanced tooling that this should not be an issue either for react or for regular js stacktraces. |
It's just that you have to write the component name several times inside of a file and if you want to rename it then you have to rename it in a bunch of places, including where it gets imported, and as your codebase grows, it creates more and more work to make a simple change like renaming. Or you have to use function syntax that you're not in love with, and if it's a default export then you'll probably name it the same thing as your file anyways. It just causes developers to have to spend more time naming things, which is one of the most difficult things in programming. |
Feature Request
Component name as props
Current behavior
You have to set
.displayName
in a second statementhttps://stackoverflow.com/questions/43356073/how-to-set-displayname-in-a-functional-component-react
Desired behavior
You can set a component's displayName by setting a displayName prop, ideally anywhere in the component hierarchy, like so:
or so:
Why
To make writing components less verbose
Other ideas:
facebook/react-devtools#1294
The text was updated successfully, but these errors were encountered: