Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my react html render is not working? [duplicate]

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>
like image 455
Neha Sharma Avatar asked Dec 01 '22 14:12

Neha Sharma


1 Answers

Your component name 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>
like image 70
duncanhall Avatar answered Dec 15 '22 11:12

duncanhall