Answer the question
In order to leave comments, you need to log in
What is the difference between css modules and styled-components?
What is the difference between css modules and styled-components? Both encapsulate styles inside components, well, a little differently, but what is the fundamental difference between these approaches?
Answer the question
In order to leave comments, you need to log in
css module work only for the elements of the component into which they are imported, and styled-components for the entire component tree.
It's short, read more here :
About styled-components based on what I read about this approach, no experience with it.
The root difference is that styled components are css-in-js, styles are written as a template string, inserted into the style attribute/tag. It’s already more difficult to associate preprocessors with this (probably there is no need for this)
css-modules is easier, you can use preprocessors, assemble them into bundles, chunks, or at least in the same style tag
If it’s very short) Read about css-in-js, that’s all should already be written
styled-components if you want everything to be compact, neatly scattered around the project, and in general if you don’t want to take a steam bath.
css modules if you want to write styles in separate files, and then run around combining them to switch styles for different states.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question