Ad

Not Able To Render Element Using React.render - ReactJS

I am a starter in ReactJS, so may be its a very basic question.

Following is my code which is throwing error in the console - SyntaxError: expected expression, got '<'

I am following the tut from here - Scotch Tut Link but unable to find out what I am doing wrong at the first step.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React Example 1</title>
    <script src="lib/react-0.11.2/build/react.js"></script>
    <script src="lib/react-0.11.2/build/JSXTransformer.js"></script>
</head>
<body>
    <div id="compOne"></div>
    <script type="text/jsx">
        React.render(
            <p>This is a test !!!</p>, 
            document.getElementById('compOne')
        );
    </script>
</body>
</html>

FYI - Path to library files are correct as I checked it in the page source.

Ad

Answer

Include /** @jsx React.DOM */ in script text/jsx , find sample below

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/0.11.2/react.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/0.11.2/JSXTransformer.js"></script>
<script type="text/jsx">
    /** @jsx React.DOM */
    React.renderComponent(<h1>Hello</h1>, document.getElementById('container'));
</script>

</body>
</html>
Ad
source: stackoverflow.com
Ad