Reputation: 64
I wonder if there is any possibility to have more than one style in React component e.g.
import React from 'react'
function App() {
const styles = {
styleOne: {
color: 'red'
},
styleTwo: {
fontSize: '2rem'
}
};
return (
<div style={styles.styleOne}>
Lorem ipsum
</div>
);
}
I want div
to have both styleOne
and styleTwo
styles. I have try to pass array of styles to style
props, but its not working.
Upvotes: 0
Views: 47
Reputation: 9769
Try this
export default function App() {
const styles = {
styleOne: {
color: 'red'
},
styleTwo: {
fontSize: '2rem'
}
};
return (
<div style={{...styles.styleOne, ...styles.styleTwo}}>
Lorem ipsum
</div>
);
}
Upvotes: 1