Want to pass class names to react components? In React, when you want to pass an interpreted expression, you have to open a pair of curly braces. Try:
1 2 3 4 5 6 7 | render () { return ( <button className={`pill ${ this.props.styleName }`}> {this.props.children} </button> ); } |
Using the classnames npm package
1 2 3 4 5 6 7 8 9 | import classnames from 'classnames'; render() { return ( <button className={classnames('pill', this.props.styleName)}> {this.props.children} </button> ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.