Skip to content
Advertisement

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement