DEV Community


(Quick tip) Easy debugging styled-component with CRA

devalnor profile image ・1 min read

(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:

Discussion (0)

Forem Open with the Forem app