Not an answer to why it breaks on IE, but a recommended approach for dealing with multiple classNames.
Use the classnames
package (https://github.com/JedWatson/classnames).
npm install classnames --save
Then you could use it like so:
import styles from './styles.scss';
import classNames from 'classnames';
function MyComponent(props) {
// we could possibly receive a class from outside the component
// as a prop.
const propClassName = props.className;
// We use `classNames` function to merge two classnames.
return (
<div className={classNames(styles.root, propClassName)}>
Hello world
</div>
)
}
This way you will still have multiple classes applied to your component without a duplicate prop declaration. If the case above, if the passed in prop is nil then only the styles.root
class is applied.
Check out the rest of their docs, you can do some cool things with classnames
, like enable a class based on a bool flag etc.
e.g.
const fullClassName = classNames(
styles.root,
{ 'active': props.active }
);
In the example above the "active" class will only be applied if props.active is truthy.
You can also use a class from the imported stylesheet using ES6 computed property names. For example:
const fullClassName = classNames(
styles.root,
{ [styles.active]: props.active }
);
As you can see, this opens up a ton of customisation options to your components.