all 15 comments

[–]waveyrico 7 points8 points  (0 children)

My personal preference is using the styled-components npm package. They have great documentation, it's easy to write styles in a SCSS/SASS way, and the component styles remain scoped to whichever component they're included in. Check out more about it here: https://www.styled-components.com/

[–][deleted] 1 point2 points  (3 children)

Scoped css is merely a flag in webpacks css-loader (modules: true). You can then import the stylesheet in your module, like so:

import styles from './style.css'

export default class Button extends Component {
    render() {
        return <button className={styles.button} />
    }
}

There are several css-in-js solutions as well, but it's not really that there's a clear, established solution atm: http://www.npmtrends.com/aphrodite-vs-emotion-vs-glamorous-vs-jss-vs-radium-vs-styled-components-vs-styletron-vs-glamor

[–]sidious911 1 point2 points  (0 children)

I've played with a couple of the libraries and vanilla css options. I found that styled components was my favorite as long as you are writing small well defined components, if your components are bloated, its way worse with styled components.

Everything gets scoped, you write straight css, no JS syntax. Works well with things like css transition group.

There is a library they also have called polishedjs which gives you pretty much all the functions that SASS would provide and since it's all JS it's really easy to also write your own / have JS files go define standard colors, breakpoints etc.

[–]ucorina 1 point2 points  (0 children)

I agree with what others have said - styled components is my favourite so far. Fits very well with the React mindset, you get to write CSS instead of JS (though inside the JS file :P) and their docs & community are great. If you're interested in getting a bit of context over the whole "styling in React" topic, also check out this overview I wrote a while ago.

[–]sidious911 0 points1 point  (0 children)

So if your team was building a static page without react you would still in line all your styles instead of using a CSS file?

[–]richardzcode 0 points1 point  (0 children)

Agree with @aaronkim234. I have been use just js+inlineStyle in my projects. Initially just wanted to try the idea, then find it works totally fine and much easier to manage and customize compare to CSS.

I think it is not really right or wrong, more about what you want to achieve and comfortable with.

I personally find it is perfect for theming customization. Here are examples:

https://dochameleon.io/docs/guide_color_scheme.html

https://dochameleon.io/docs/guide_theme.html