DEV Community

maxime.io
maxime.io

Posted on

(Quick tip) Easy debugging styled-component with CRA

(This is a just quick tip not an elaborated post sorry)

Thanks to Babel Macro, we don't need to eject our CRA project.

  1. Use import styled from 'styled-components/macro'
  2. Install npm install babel-plugin-macros
  3. Create .babelrc in your project root
  4. Then add this to your .babelrc
{ 
   "plugins": ["babel-plugin-styled-components"]
}

This option enhances the attached CSS class name on each component with richer output to help identify your components in the DOM without React DevTools.

It also allows you to see the component's displayName in React DevTools.

Voilà, enjoy!

More info: https://styled-components.com/docs/tooling#babel-macro

Top comments (0)