Home > Mobile >  how do I add a dollar sign(before braces) as a string in React?
how do I add a dollar sign(before braces) as a string in React?

Time:04-26

function Price(props){
<span>This item is ${props.price}</span>
}

I want to use $ as a string, but it doesn't work due to JSX syntax. how can I fix it?

CodePudding user response:

This code will display '$' as a string, '$' is not a special character in JSX, you may be thinking JQuery

CodePudding user response:

This should work as is. Also, You could try another approach using template literal syntax:

{`Hello the price is $${price}.`}
  • Related