Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
-3
rated 0 times [  1] [ 4]  / answers: 1 / hits: 39592  / 6 Years ago, mon, april 9, 2018, 12:00:00

I want to use this but props


<section class="slider" data-slick='{"slidesToShow": 3,"autoplay": true,  "responsive": [{"breakpoint":600,"settings":{"slidesToShow": 2}}]}'>

which should give


<section class="slider" data-slick='{"slidesToShow":${props.number},"autoplay": ${props.autoplay},  "responsive": [{"breakpoint":${props.breakpoint},"settings":{"slidesToShow": ${props.show}}}]}'>

but as it's inside quote I try to use
Template literals with babel


like this


"babel": {
"presets": [
"es2015",
"stage-3"
],
"plugins": [
"transform-object-rest-spread",
[
"transform-react-jsx",
{
"pragma": "wp.element.createElement"
}

],["transform-es2015-template-literals"]
]
}

but it didn't get the value of my props it just send it like a quote.


How should I use transform-es2015-template-literals to get my props value inside this quote


More From » reactjs

 Answers
37

You don't need to add the plugin to transform them, it's your syntax which is wrong.



You need to use backticks: ` instead of regular ticks (apostrophe): ' . And use curly brackets around that.



<section 
class=slider
data-slick={`{slidesToShow:${props.number},autoplay: ${props.autoplay}, responsive: [{breakpoint:${props.breakpoint},settings:{slidesToShow: ${props.show}}}]}`}
>

[#54713] Friday, April 6, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryanulyssesb

Total Points: 91
Total Questions: 105
Total Answers: 102

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
ryanulyssesb questions
Sat, Mar 20, 21, 00:00, 3 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
Mon, Mar 9, 20, 00:00, 4 Years ago
Sun, Jul 7, 19, 00:00, 5 Years ago
;