Konstantin Victoria
Konstantin Victoria

Reputation: 21

React - Modify component style via javascript or css?

Is it better to style your components in the component's .jsx file, or in a separate .css file? Also, is there a performance difference?

Upvotes: 0

Views: 129

Answers (1)

Kasey Chang
Kasey Chang

Reputation: 542

Having a separate CSS file makes "styling" the component more... discrete than modifying the in-line styles. It also makes it possible to combine the changes more easily later with something like SASS/SCSS or similar tools.

On the other hand, the disadvantage of having a separate stylesheet is the increased difficulty in doing live modifications to the style.

Then there are tools like Radium (for React.js) that lets you manipulate style objects as JavaScript objects.

It really depends on your programming style, and "corporate guidelines", if any.

Upvotes: 1

Related Questions