Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  91] [ 5]  / answers: 1 / hits: 19879  / 5 Years ago, tue, september 10, 2019, 12:00:00

Is it possible to use map array data (${adv_event.title}) inside a react-structured-data JSX?



I tried adding backticks with no success: name: `${adv_event.title}`,



Attempt 1:



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


Error:




296:31 warning Unexpected template string expression
no-template-curly-in-string



More From » reactjs

 Answers
47

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.


[#51670] Tuesday, September 3, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryankiah

Total Points: 183
Total Questions: 99
Total Answers: 112

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;