React Book - Chapter 15

In previous chapters, the author talked about having the style in the component, using style={} … but in this chapter the style was held separately in a css file. Is there a reason for this? When should I use which way?
thx.

Hi Martin - you can use whichever approach you prefer! The way I concluded that chapter is:

With that said, you should pick and choose the techniques that make the most sense for your situation. While I am biased towards React’s way of solving our UI development problems, I’ll do my best to highlight alternate or conventional methods as well. Tying that back to what we saw here, using CSS style rules with your React content is totally OK as long as you made the decision knowing the things you gain as well as lose by doing so.

To be more specific, if you are planning on making your component reusable as part of a library of components other people will rely on, then placing the CSS inside a JavaScript object is better. For all other situations, going with the old-school <style> tag approach is easier.

:slight_smile:

1 Like

thx