re: React Beginner Question Thread ⚛ VIEW POST

re: Hey Dan, thanks for doing this. What would you say is the latest best practice for approaching CSS/styling in React?

Liana, I don't know if this could be considered a "latest best practice", but it is something I've started doing for my own projects, which is to import CSS files as modules import "./component-style.css" inside the component file, then use Webpack to compile it.

You can avoid errors during testing using ignore-css module.

If you research a bit there are very interesting articles on the topic, and it has helped me to keep my CSS modular and clean.

You can even keep your CSS file close to your component.js and component.test.js files in the same folder, which for me at least is very practical when working on any particular component.

Hope it helps!


Or you can just use styled-components and all that will be very natural with zero dead CSS code :P

code of conduct - report abuse