I changed my file Order.css to Order.module.css. And now I need to transform this condition from
const firstNameClass = firstNameInputHasError ? 'form-control invalid' : 'form-control'; ... <div className={firstNameClass}> ... </div> in something like this
const firstNameClass = firstNameInputHasError ? classes['form-control'] + classes['invalid'] : classes['form-control']; first-line works fine when the name of the file is Order.css. The second line doesn't work.
Updated. Thanks to chenc that recommended classnames package
My solution
import classes from './Order.module.css'; import classNames from "classnames/bind"; let classNameBound = classNames.bind(classes); const firstNameClass = classNameBound( classes["form-control"], {invalid: firstNameInputHasError} ); Second solution without classnames package
const firstNameClass = `${classes["form-control"]} ${firstNameInputHasError ? classes.invalid : ''}`;