I'm returning the following HTML in React.
<div
className={ props.className }
data-slide='{"arrows": true, "slidesToShow": 3, "slidesToScroll": 1}'>
</div>
It returns the following which is ok
<div class="some-class" data-slide="{"arrows": true, "slidesToShow": 3, "slidesToScroll": 1}"></div>
However, I want the value for arrows to be a variable named arrowsVal which I'm setting in my React component.
I tried:
<div
className={ props.className }
data-slide='{"arrows":' + arrowsVal + ', "slidesToShow": 3, "slidesToScroll": 1}'>
</div>
and
<div
className={ props.className }
data-slide='{"arrows": `${arrowsVal}`, "slidesToShow": 3, "slidesToScroll": 1}'>
</div>
but it does not work.
data-slide={createDataSlideString()}, and then before yourrender'sreturn(),function createDataSlideString(){...code that creates your string}. This makes it easier to avoid JSX character-escape issues in your expressions.