Render curly braces as plain text in React/JSX
If you'd like to render curly braces as plain text within a JSX document simply use the HTML character codes.
Left Curly Brace { : {
Right Curly Brace } : }
I think the issue is just a typo. You have this:
return (<p>{"{{}}"}<p>)
but you need this (note the closing p
tag instead of another opening one):
return (<p>{"{{}}"}</p>)
If you are in a situation where you can't use {
and }
, then you can use custom code:
export default class Component extends React.Component {
render () {
return (
Some object {'{'}id: 1{'}'}
)
}
}
Which will output the text Some object {id: 1}
Update: Changed it to a better solution, thanks to @xec
You can even use string interpolation in ES6. Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them. Template literals are enclosed by the backtick (` `) (grave accent) character instead of double or single quotes.
eg: return (<p>{`{{}}`}</p>)