Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading