U r s u s U r s u s -5 years ago 546
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.

Answer Source

Ah, my bad. I forgot the curly brackets.

This works

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

and this would also work

id={'input-add-' + i}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download