0

i have this code so far and trying to use ES6 syntax to create buttons onto webpage

import React from 'react';
import ReactDOM from 'react-dom';

class CustomButton extends React.Component {
  render() {
    return <button>{this.props.text}</button>
  };
};

class Element extends React.Component {
  render() {
    return (
      <div>
        <CustomButton text="I" />
        <CustomButton text="know" />
        <CustomButton text="React!" />
      </div>
    );
  };
};

ReactDOM.render(
  Element,
  document.querySelector('#root')
);

however nothing is being created on the web page.

0

1 Answer 1

3

You are using the render part wrong. You are defining a component there so, it should be like that:

ReactDOM.render(
  <Element />,
  document.querySelector('#root')
);

Your Element is not a JSX element actually, it is a class component so you should use it properly.

const foo = <div>Foo</div>;

ReactDOM.render(
  foo,
  document.querySelector('#root')
);

This works because foo is an element, it is not a class or a functional component.

See for more.

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

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.