U r s u s U r s u s - 7 months ago 234
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 (

is the mapped element index)

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


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.


Ah, my bad. I forgot the curly brackets.

This works

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

and this would also work

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