2

How do I combine a javascript variable with a string? Do I have to concat the variable?

{ /* JSX + Bootstrap */ }
<div className={s.container} + "col-md-offset-4 col-md-4 well">

Edit: Thank you for the help. Here's the error I'm getting

<div className={'col-md-offset-4 col-md-4 well' + s.container}>
// Error: Unexpected string concatenation

Thank you for the suggestions... Here's the error I get when I follow these docs http://eslint.org/docs/2.0.0/rules/prefer-template

Module build failed: SyntaxError: JSX value should be either an expression or a quoted JSX text (23:23)

  21 |     return (
  22 |       <div className={s.root}>
> 23 |         <div className=`col-md-offset-4 col-md-4 well ${s.container}`>
Tyler L
  • 835
  • 2
  • 16
  • 28

1 Answers1

5

@Poke and @Andrew Li deserves credit for figuring this one out. You need to follow the docs but also put it inside javascript with the curly brackets

<div className={`col-md-offset-4 col-md-4 well ${s.container}`}>
Tyler L
  • 835
  • 2
  • 16
  • 28
  • Some days, I think those backticks are the best thing ever to happen to strings in javascript. It's so much neater than spamming `+` symbols or using `join` on arrays of strings. – freethebees Dec 29 '20 at 17:54