Ad

React HTMLtoJSX Does Not Convert Curly Brackets

- 1 answer

I am experiencing a problem with the HTMLtoJSX converter (npm: htmltojsx), the same converter as officially displayed on https://facebook.github.io/react/html-jsx.html.

The HTML-code <div>{</div> is compiled to the following JSX-code:

<div>{</div>

The JSX code fails with the following error:

Uncaught SyntaxError: embedded: Unexpected token (7:18)
   5 | var Hello = React.createClass({
   6 |   render: function() {
>  7 |     return <div>{</div>;
     |                   ^
   8 |   }
   9 | });

Test: https://jsfiddle.net/69z2wepo/28714/

Does anyone know a solution for the problem?

Ad

Answer

In JSX curly brackets are used to wrap javascript expressions. You can display bracket like this:

return <div>{'{'}</div>;
Ad
source: stackoverflow.com
Ad