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

Have component names inside classnames when in dev mode #521

Open
nikitavoloboev opened this issue Jan 3, 2023 · 2 comments
Open

Have component names inside classnames when in dev mode #521

nikitavoloboev opened this issue Jan 3, 2023 · 2 comments

Comments

@nikitavoloboev
Copy link

nikitavoloboev commented Jan 3, 2023

Would be super helpful. Currently the classnames are like this go3532050352.

This is fine for production but for dev mode I'd love for it to be something like Wrapper3532050352 assuming the styled element is named Wrapper.

@cristianbote
Copy link
Owner

Hey @nikitavoloboev, there's a way to pass in a custom className to a certain styled component. Take this example:

const Button = styled("button")`
  background: tomato;
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem;
`;

// Pass along a custom `className` to be added to each `<Button />` element
Button.className = "Button";

The above will render to html something like this:

<button class="go2965422667 Button">Tomato</button>

Hopefully this will help you.

@nikitavoloboev
Copy link
Author

nikitavoloboev commented Jan 9, 2023

This won't help as I don't want to add this manually for every styled component.

Basically I want to see in DOM quickly which DOM element corresponds to which React component name. Only when in dev of course.

Can this be done perhaps as post processing step via something like https://vitejs.dev

And the command you sent above. Like statically analyzing all code, finding all styled components, before doing dev build, creating a file with things like <button class="go2965422667 Button">Tomato</button>.

Basically I want this to happen under the hood when I start dev server. In production it does what it does now.

Willing to contribute code for this as it will help me a lot.

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

2 participants