33

I have created a simple React component which displays another react component. But it doesn't render in browser :

class Home extends React.Component {
  render() {
    return (
      <div>
        <map/>
      </div>   
    );
  }
}

var map = React.createClass({
   render: function() {
      return (
          <div id="map-canvas">
            <span>hello</span>
          </div>
      );
    }
});

I'm expecting the hello to show up on the screen, but nothing shows up and when I inspect the element all I can see is

<map data-reactid=".0.0"></map>

Can any one point our what might be wrong.

0

2 Answers 2

85

JSX expects component tags to be capitalized. Otherwise, it will just create a DOM element with the provided tag. See HTML Tags vs. React Components.

<map /> compiles to React.createElement("map", {}); while <Map /> compiles to React.createElement(Map, {});.

Just rename map to Map and you're good.

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

5 Comments

well that gives another error Uncaught TypeError: Cannot read property 'toUpperCase' of undefined ReactDefaultInjection.js:53
Make sure that Map is correctly defined in the context of your App::render method. Also, be aware that in ES6, Map is a standard built-in object, so you might want to rename your component to something else.
Ok.. I renamed it to MyMap but still the same error.
Moving MyMap above Home resolved the issue. Thanks anyways .. :)
This behaviour is not at all intuitive I was expecting <myComponent> and <MyComponent> do the same, but I can imagine why is behaving like this. kudos for your help.
1

Just make sure that variable which you declare for creating components starts with a uppercase:-Just Like this

var Map = React.createClass({
 //Your Code here

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.