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?
JavaScript
x
12
12
1
class Strick_ extends React. Component {
2
constructor() {
3
super();
4
this.state = { color: "red" };
5
}
6
render() {
7
8
return <h1> this color {this.state.color} </h1>;
9
}
10
}
11
ReactDom.render(Strick_, document.getElementById("root"));
12
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.
JavaScript
1
15
15
1
class Strick_ extends React.Component {
2
constructor() {
3
super();
4
this.state = { color: "red" };
5
}
6
render() {
7
8
return <h1> this color {this.state.color} </h1>;
9
}
10
}
11
12
// you need to pass as element component <Component/>
13
ReactDom.render(<Strick_/>, document.getElementById("root"));
14
15
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].