Philip7899
Philip7899

Reputation: 4687

React not working. Error says (index):13 Uncaught SyntaxError: Unexpected token <

I am new to React and just trying to build a simple component to display to the page. For some reason I am getting the error:

(index):13 Uncaught SyntaxError: Unexpected token <

Here is my code:

<html>
<head>
    <title></title>
</head>
<body>
    <div id="yolo"></div>
    <script src="react.js"></script>
    <script src="react-dom.js"></script>
    <script>
        var Yolo = React.createClass({

            render: function(){
                return <h1>Waddup doc?</h1>;
            }
        });

        ReactDOM.render(
            <Yolo />,
            document.getElementById('yolo')
        );
    </script>
</body>
</html>

Upvotes: 0

Views: 311

Answers (2)

user5738822
user5738822

Reputation:

if you dont want use JSX try this syntax :

  var Yolo = React.createClass({

            render: function render(){
                return React.createElement(
                "h1",
                null,
               "Waddup doc? "
              );
            }
        });

ReactDOM.render(React.createElement(Yolo), mountNode);

more examples of pure javascript for react js exist in this link in compile tab of each example.I Hope It Can Help You.

Upvotes: 1

zackify
zackify

Reputation: 5434

You can't use JSX if you aren't using something that transpiles it. If you use create-react-app it will handle this problem for you. https://github.com/facebookincubator/create-react-app If you want your example to work, you would have to replace the JSX with React.createElement, or use an in browser JSX transformer.

Edit: If you want to play around with a script tag, remove react and react-dom and use this <script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>

Upvotes: 1

Related Questions