Home > OS >  Why are showing blank page in reactjs?
Why are showing blank page in reactjs?

Time:07-30

I am using class and constructor in react-js but this program does not error is thrown in console. show a message only blank. what is wrong?

class Strick_ extends React. Component {
      constructor() {
        super();
        this.state = { color: "red" };
      }
      render() {
        
        return <h1> this color {this.state.color} </h1>;
      }
    }
    ReactDom.render(Strick_, document.getElementById("root"));

CodePudding user response:

You need to pass it as <Component />. And Still doesn't work then add your index.html, there might be the issue then.

class Strick_ extends React.Component {
      constructor() {
        super();
        this.state = { color: "red" };
      }
      render() {
        
        return <h1> this color {this.state.color} </h1>;
      }
    }

// you need to pass as element component <Component/>
ReactDom.render(<Strick_/>, document.getElementById("root")); 

PS: If you want to render only element only html element then you can do as you did and same is mentioned in docs. And you should return element from Component [Ref].

CodePudding user response:

I suppose the issue is the space between React. and Component.

  • Related