Writing an inline style in js,
const styles = {
background: 'blue',
color: 'white'
}
and using it in the JSX as below
<div style={styles}> I am a div </div>
Writing the styles using 'styled components',
const Div= styled.div`
background: 'blue',
color: 'white'
`
and using it like,
<Div> I am a Div </Div>
Here what is the difference in using a css-in-js library and using the inline styles.
First, your styled.div
example is wrong, as in CSS-in-JS you write actual CSS and not an Object-like style:
// "Real CSS"
const Div= styled.div`
background: blue;
color: white;
`
Second, CSS classes are generally better, also, inline styles are considered bad practice as it is hard to re-use and maintain styles.
CSS classes are generally better for performance than inline styles.
So in conclusion: