0

My code is throwing syntax error at line <div>Hello World!</div>

This is my code

<!DOCTYPE html>
<html>
<head>
    <script src="libs/react.min.js"></script>
    <script src="libs/react-dom.min.js"></script>
</head>
<body>
    <div id="main">

    </div>

<script>
    var MessageComponent = React.createClass({
        render: function() {
            return (

                <div>Hello World!</div>
            );
        }
    });

    ReactDOM.render(
        <MessageComponent message="Lorem" />,
        document.body
    );
</script>    
</body>
</html>

What could be the issue?

0

2 Answers 2

3

You are using the JSX syntactic sugar to build your UI component and browsers don't understand that.

You will have to transpile it to JS first before it can work.

Sign up to request clarification or add additional context in comments.

Comments

0

I added Babel in the page

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>

and added type="text/babel" to the script tag. That fixed the issue

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.