Using the css-in-js method to add classes to a react component, how do I add multiple components?
Here is the classes variable:
const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap'
},
spacious: {
padding: 10
},
});
Here is how I used it:
return (
<div className={ this.props.classes.container }>
The above works, but is there a way to add both classes, without using the classNames
npm package? Something like:
<div className={ this.props.classes.container + this.props.classes.spacious}>
You can also use the extend property (the jss-extend plugin is enabled by default):
Yes, jss-composes provides you this:
And then you just use classes.spacious.
you can install this package
https://github.com/JedWatson/classnames
and then use it like this
you can use string interpolation:
To have multiple classes applied to a component, wrap the classes you would like to apply within classNames.
For example, in your situation, your code should look like this,
Make sure that you import classNames!!!
Have a look at material ui documentation where they use multiple classes in one component to create a customized button