Help with React :Writing a component

Help with React :Writing a component
0

Tell us what’s happening:
I’m pretty sure my code is correct, but it doesn’t render to the DOM.

Please help!!

Your code so far


// change code below this line
class MyComponent extends React.Component {
  constructor(props) {
    super(props);
  }
  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_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/write-a-react-component-from-scratch

You’re not crazy. You will need to wrap the <h1> in a <div> but it should render without.
-J

1 Like

Try to replace MyComponent with

<MyComponent />

inside the call to ReactDOM.render()

1 Like

Thanks!
I totally forgot about that!