React Type error cannot read properties of null even though its not null

Viewed 40

code image

1

this is my first question on stackoverflow please help me out. Thanks. I am trying to simply print out the state property in a div element:

super();
this.state = {
  city: "New York"
};

and then i try to print it out in a div element like this:

{this.state.city}

but it gives me the error Cannot read properties of null (reading 'city') even though its not null

1 Answers

You are trying to get the state that is defined in the Main component. Move the constructor to the App component.

Related