2

When I use a variable starting with a small letter, the page is showing nothing. If I change the variable name to start with uppercase (HelloWorld) the page is showing the content.

<script type="text/jsx">
 var helloWorld = React.createClass({
    render : function () {
                return (
                    <div>
                    <h1>Hello World</h1>
                    </div>
                    );
    }
 });

 React.render(<helloWorld/> , document.body);
</script>

Can anyone tell me why this is happening?

rudolph1024
  • 962
  • 1
  • 12
  • 32
Dangling_pointer
  • 4,633
  • 2
  • 14
  • 16

1 Answers1

5

As of React v0.12., upper-case components are the React convention for distinguishing between components and HTML tags.

From the React documentation under the HTML Tags vs. React Components header:

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

var MyComponent = React.createClass({/*...*/});
var myElement = <MyComponent someProperty={true} />;
React.render(myElement, document.getElementById('example'));

React's JSX uses the upper vs. lower case convention to distinguish between local component classes and HTML tags.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
grdevphl
  • 690
  • 1
  • 6
  • 16