简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM