DEV Community

maxime.io
maxime.io

Posted on

1 3

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay