U r s u s U r s u s - 5 months ago 171
Javascript Question

Babel string interpolation error

I have a bunch of input elements to which I want to assign unique ids.

However, the following string interpolation (

i
is the mapped element index)

id = `input-add-${i}`


returns

Parsing error: JSX value should be either an expression or a quoted JSX text


I use interpolation successfully elsewhere, so I don't understand what I am doing wrong here.

Answer

Ah, my bad. I forgot the curly brackets.

This works

{ id={`input-add-${i}`} }

and this would also work

id={'input-add-' + i}