javascript – How to correctly include styles in React

Question:

Actually the question is higher. I saw some styles I import into the component, is it possible to simply include styles in html? Which way is better?

Answer:

By and large, the only reason to import css into components is to get away from one global css file, solving all the problems that accompany it in large projects:

  1. Class name intersection
  2. Difficulty navigating and finding the right classes in a huge file
  3. Problems of detecting "dead code" in these footcloths

If you're not sure whether to do the "old fashioned" way of importing everything you need into index.html, or use the so-called. css modules, then use the first: most likely the problems listed above do not concern you.

Scroll to Top