0

Why is my second component not loading in the first component? Here is the code:

var ComponentOne = React.createClass({
    render: function(){
      return(
        <div>
          <h1>ComponentOne</h1>
          <componentTwo />
        </div>
      )
    },
  });

  var componentTwo = React.createClass({
    render: function(){
      return(
        <div>
          <h2> componentTwo </h2>
        </div>
      )
    }
  })

Here I have added second component in the first component by <componentTwo /> but still not displaying.

Here is a Plunker.

1

1 Answer 1

2

Just start your component2 with capital letter and it would work

something like

var ComponentOne = React.createClass({
    render: function(){
      return(
        <div>
          <h1>ComponentOne</h1>
          <ComponentTwo />
        </div>
      )
    },
  });

  var ComponentTwo = React.createClass({
    render: function(){
      return(
        <div>
          <h2> componentTwo </h2>
        </div>
      )
    }
  })

Why capitals? explanation can be found here https://stackoverflow.com/a/30373505/2551236

Hope this helps!

Good luck!

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

3 Comments

Can I know why capitals for components name.
@RamanaUday custom components must start with capital letters as built in components (div, h1, p, etc.) use lowercase. See the documentation for more details.
@RamanaUday if this answer helps you, please accept it so that others facing same issue can get the problem solved

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.