Skip to content

Fall back to function.name if displayName is not defined#47

Open
soup-in-boots wants to merge 4 commits into
masterfrom
fallback-name
Open

Fall back to function.name if displayName is not defined#47
soup-in-boots wants to merge 4 commits into
masterfrom
fallback-name

Conversation

@soup-in-boots
Copy link
Copy Markdown

Fall back to function name if displayName is not defined on a function-type component. Helps with development environments, but is still susceptible to minification or obfuscation mangling the name of the component.

Comment thread src/__tests__/main.test.js Outdated
NoClickHandler.displayName = 'NoClickHandler';

describe('logrocket-react', () => {
function FunctionComponentWithoutDisplayName(props) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Would it be possible to create some format of factory function to create these function components to reduce duplication?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, definitely possible. I'll see what I can whip up!

@soup-in-boots
Copy link
Copy Markdown
Author

soup-in-boots commented May 29, 2026

Consolidated the function component definitions with a simple factory. I noticed I could consolidate the class components as well, so I did. I considered the nested series of components, but they're simple and varied enough that I didn't feel I could make them much more concise.

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