Use the package classnames:
install:
npm install classnames
import:
import classNames from 'classnames';
use it :)
const ButtonTemplate = props => {
const themed = classNames('btn-', props.theme)
const themedButton = classNames(
styles.btn,
styles[themed],
themed,
{ disabled: props.disabled }
);
return (
<button className={themedButton} type='button' onClick={props.onClick}>{props.children}</button>
)
}
It can be very helpful as we will be facing similar situations throughout developing a big project. Here are some tricks copied from the original documentation:
classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ 'foo-bar': true }); // => 'foo-bar'
classNames({ 'foo-bar': false }); // => ''
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'
// lots of arguments of various types
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
...and there are more. You should really take a look at it and give it a try.