2

whats the difference between using an inline style object for react components and using normal css class through className attribute , even if i want to change some styles on a certain event i can just change the className , so whats the best way to go with and why ?

Cheers

2 Answers 2

5

I would go for external CSS classes. If you would not use it, use will not be able to reuse common styles. Also, in the end your code will be bigger(more chars - more size) once you finish the project.

Inline styles take more size in the DOM, are converted more slowly from VDOM (have probably a bigger impact on memory), and take more time to be handled by the browser.

This is taken from an great article that I think will make things clear for you.

Sign up to request clarification or add additional context in comments.

Comments

4

It's really all a matter of preference. Using inline styles gives you more componetized styles -- meaning you don't need to worry about the gotchas of CSS overriding what you want for that particular component. However, when you do this you don't get the benefits of CSS and using stylesheets to style your components becomes much harder.

Do what makes sense.

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.