I'm rendering the following HTML with JSX
<div data-things="{"somethingOne": 1, "somethingTwo": 22, "somethingThree": 'some string'}">
</div>
In JSX I have
const data = `{
"somethingOne": ${valueOne},
"somethingTwo": ${valueTwo},
"somethingThree": ${valueThree}
}`;
and returning
<div data-things={ data }><div>
This works fine but now I am trying to add conditions in the template literal to show property-value pairs only if a value exists.
I tried many variations including:
const data = `{
"somethingOne": ${valueOne},
${valueTwo} && "somethingTwo": ${valueTwo},
"somethingThree": ${valueThree}
}`;
The condition renders:
22 && "initialSlide": 22,
It shows the value but returns the conditional statement syntax instead of processing it.
How can I make the condition work? I have to add the condition for each one.