4

I'm trying to render a react component inside a html page. what i did so far is implementing react like this

var component =  React.createClass({
render: function(){
var testStyle = { fontSize: '18px', marginRight: '20px'};
return (
  <div>

    <h1>Hello React</h1>
    <div><ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
    </ul></div>
  </div>

  )

  }
  });

 ReactDOM.render(< component/>,
 document.getElementById('content')
 );

and in the HTML page i have this

<div id="content"></div>

when i inspect the HTMl page i find that inside the div i have an empty component like this

<component data-reactroot=""></component>

what am i doing wrong here

1 Answer 1

5

A React component must always start with a capital letter, otherwise React interprets it as a simple HTML element.

Capitalized types indicate that the JSX tag is referring to a React component.


That being said, define

const Component = React.createClass...

and then render like

ReactDOM.render(<Component />, 
  document.getElementById('content')
);
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer; that's what was missing it's now working great, i've been following a tutorial in Youtube and i guess i didn't notice the Capitalized letter
Im glad it worked. Please accept the answer it really helps me out - the check mark next to the answer :-)

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.