Neha Sharma Neha Sharma - 2 months ago 6
React JSX Question

Why my react html render is not working?

I have written a simple react component but it is not rendering the HTML on the page. Could someone please guide me where I am doing wrong?

http://codepen.io/NehhaSharma/pen/EVNdJJ?editors=101

Thanks.

<div id="content"></div>
<script type="text/jsx">

var newComponent = React.createClass({
render : function(){
return (
<h2>My Name is React</h2>
);
}

});

React.render(<newComponent/>,document.getElementById('content'));
</script>

Answer

Your class should start with an upper-case letter. From the React Docs:

To render a React Component, just create a local variable that starts with an upper-case letter:

The following will render as expected:

<div id="content"></div>
<script type="text/jsx">

var NewComponent = React.createClass({
    render : function(){
        return (
            <h2>My Name is React</h2>
        );
    }

});

React.render(<NewComponent/>,document.getElementById('content'));
</script>