question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an option to include the component's displayName in the generated class names

See original GitHub issue

Hi this is feature request for an option to include the component’s displayName in the generated class names, something like MyComponent_u2jd38.

Without this, it is very hard identify where styling issues comes from when using Dev Tools to investigate. After a few weeks using styled-components in my team, this issue has been raised by several people. We transitioned from css-modules where we had this feature and now we miss it a lot.

FYI: We would probably enable this option for development builds only.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
olivierbeaulieucommented, Sep 16, 2019

For those using create react app, you can solve this without ejecting by using babel macros.

Simply import styled-components/macro instead of the usual styled-components. You don’t need to install anything special. The downside is that you will need to import this everywhere.

Example:

import styled from 'styled-components/macro';

const MyStyledComponent = styled`
  color: pink;
`;

When used, this component will have a nice readable className like MyStyledComponent_fa09we8.

2reactions
VictorChencommented, Jan 10, 2019

For people using create react app, is there any way to solve this without ejecting?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled Components adding component name as class name
I have a component called AlphaBarWrapper with a styled component inside of it called StyledAlphabar . Styled Components is adding ...
Read more >
How to Control Class Names in Styled Components
A meaningful class name can be composed of namespace , displayName , and fileName , in addition to the default name. Maximally, we...
Read more >
ASP.NET Core Blazor forms and input components
Learn how to use forms with field validation and built-in input components in Blazor.
Read more >
Documenting components - Vue Styleguidist
Vue styleguidist generates documentation for your components based on the comments in your source code declarations and Readme files. Note: See examples of ......
Read more >
Context - React
createContext('light'); class App extends React.Component { render() { // Use a Provider to pass the current theme to the tree below. // Any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found