Why do I get an unexpected template string expression error? Why do I get an unexpected template string expression error? reactjs reactjs

Why do I get an unexpected template string expression error?


This is an warning generated by ESLint: no-template-curly-in-string

Disallow template literal placeholder syntax in regular strings (no-template-curly-in-string)

ECMAScript 6 allows programmers to create strings containing variable or expressions using template literals, instead of string concatenation, by writing expressions like ${variable} between two backtick quotes (`). It can be easy to use the wrong quotes when wanting to use template literals, by writing "${variable}", and end up with the literal value "${variable}" instead of a string containing the value of the injected expressions.

If you want to just assign that variable you should do this:

<Generic jsonldtype="event" schema={{    name: adv_event.title,     description: "",    startDate: "YYYY-MM-DDT:HH:MM",    endDate: "YYYY-MM-DDT:HH:MM",    image: "",}}>

A template string is not needed in your case.


I was stuck with similar issue until I realized that the single or double quotes (''/ "") should not be used. The variable should be enclosed between backticks only (``).