1

I am learning React and realized that you can use either real CSS by importing a CSS file, or you can use JS which has CSS-like code using camel cases.

Example for pure CSS: import './AppStyle.css' which contains background-color: black;

Example for JS version: const AppStyle = { backgroundColor: "black" }

Which one is better to use and why? Or maybe they’re both fine?

3 Answers 3

6
  • Writing CSS allows all the benefits of CSS (like selectors, media query).
  • In inline styles, you write Object-like styles vs. actual CSS.
  • Code readability is worst in inline style implementation, while managing styles using the CSS is easy to maintain.
  • The inline styles take more space in DOM because all the styles are defined internally along with the DOM element, while CSS is described separately, creating no issues for the compiler while compiling the file.
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! You answered my question perfectly!
In 4 minutes when it allows me to say this answered my question, I will.
1

There is ups and down with both solutions, you can achieve the same result with both, so it comes down to you want styling solution you prefer

Comments

0

Based on my experience,JSX and CSS are different technologies to solve the styling problem.

Good points of css:

  • css selectors
  • styling into css files

Good points of js:

Recommendation: Try to use one, it reduce the complexity and documentation to read.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.