Write a React Component From Scratch/need help

Tell us what’s happening:

Your code so far


// change code below this line
class MyComponent extends React.Component {
render () {
  return (
    React.createElement("div",
    { className: "container"},
    React.createElement("h1", null, "My First React Component!")
    )
  );
}
}
ReactDOM.render(React.createElement(MyComponent, null), );

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Write a React Component from Scratch

Link to the challenge:

I am doing something wrong, obviously. But I can’t figure out what. Please help! Thank you

First of all, build it with JSX, not with React.createElement.

Secondly, your ReactDOM.render should have two parameters. The first one is the component. The second is a reference to the node on the DOM where you are rendering this. You do that with document.getElementById. That is what the last paragraph of the instructions is trying to tell you.

React is confusing when you start it. Just keep at it. Let us know if you need further assistance.

1 Like

Tell us what’s happening:

Your code so far


// change code below this line
class MyComponent extends React.Component {
render() {
  return {
    <h1>My First React Component!</h1>
  };
}
}

ReactDOM.render(<MyComponent/>, document.getElementById('challenge-node'))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Write a React Component from Scratch

Dang it! What am I doing wrong now?

Nevermind! Nevermind! Nevermind! I got it!

It should have been
return (ect...)

Just an FYI. If you are only returning one element return someJSX you can also leave off the parentheses.

return <h1>My First React Component!</h1>
1 Like