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

(Feature request): good name of components generated by stitches inside react dev tools #1124

Open
Aarbel opened this issue Nov 29, 2022 · 3 comments

Comments

@Aarbel
Copy link

Aarbel commented Nov 29, 2022

Hi stiches team,

is there a way that generated stitches components get the right component name inside react developper tools ?
It's quite hard to read inside the react chrome inspector.
In the examples bellow i would like to see ScrollableContent instead of Styled.div inside the react chrome inspector

image

image

@shawnbot
Copy link

shawnbot commented Dec 8, 2022

Though I could see Stitches supporting a displayName like this...

const ScrollableContent = styled('div', {
  displayName: 'ScrollableContent',
  ...styles
})

It's probably simpler to just assign it yourself:

ScrollableContent.displayName = 'ScrollableContent'

Or, in a single expression (less readable, IMO):

const ScrollableContent = Object.assign(style('div', {
  ...styles
}), {
  displayName: 'ScrollableContent'
})

@shawnbot
Copy link

shawnbot commented Dec 8, 2022

Related: #1104 is an open issue to document the styled.withConfig() API, which supports a displayName and (if I'm reading the code correctly) assigns it here:

styledComponent.displayName = displayName || `Styled.${DefaultType.displayName || DefaultType.name || DefaultType}`

So, in your case, I think this will work:

const ScrollableContent = styled.withConfig({ displayName: 'ScrollableContent' })('div', { ...styles })

which—again, if I'm reading this correctly—will also inject ScrollableContent into the generated CSS class:

const componentNamePrefix = displayName ? ('c-' + displayName +'') : 'c'
const className = `${toTailDashed(config.prefix)}${componentNamePrefix}-${hash}`

@Aarbel
Copy link
Author

Aarbel commented Dec 8, 2022

Thanks a lot @shawnbot, i implement it and give you a feedback of the efficiency of the api

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