Fu-Han Zhang
Fu-Han Zhang

Reputation: 75

How can I mix string and JSX in react properties?

I have JSX code like this:

<Item cate="capital" parm={"11"+{<span>.55</span>}} small="Feb" />

I think there's nothing wrong but my browser keeps telling me "Unexpected token".

how can I fix it?

Upvotes: 0

Views: 561

Answers (2)

user5738822
user5738822

Reputation:

you can use ES6 template, try this:

<Item cate="capital" parm={`11${<span>.55</span>}`} small="Feb" />

read more about ES6 template

Upvotes: 1

Andrey Saleba
Andrey Saleba

Reputation: 2197

Proper way of doing it: Pass it to your item component:

<Item cate="capital" parm={<span>.55</span>}
small="Feb"
addToParm="11" />

And just use it in your Item component:

<div>
    {this.props.addToParm}
    {this.props.parm}
</div>

Upvotes: 0

Related Questions