score:3

Accepted answer

First initialize your state in your constructor like this

constructor(props) {
        super(props);
        this.state = {users : []} //initialize as array
    }

Then instead of that.state = {users: json}; set your state using

that.setState({ users: json });

score:0

You already got the answer to use setState({ users: json }), which is right.

As an alternative to initializing the array value like abul said, you could also do a conditional render, depending on the component state. I.e you can render a different component if the users aren't loaded yet.

render() {
   const users = this.state.users;
   return !users ?
      <p>Loading..</p> : 
      <YourComponent users={users} />;
}

score:1

You should use the React setState() method.

that.setState({ users: json });

Related Query

More Query from same tag