ankit chauhan
ankit chauhan

Reputation: 5

Why are showing blank page in reactjs?

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"));

Upvotes: 0

Views: 494

Answers (2)

GodWin1100
GodWin1100

Reputation: 1420

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].

Upvotes: 2

William Mai
William Mai

Reputation: 104

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

Upvotes: -1

Related Questions