Answer the question
In order to leave comments, you need to log in
How to correctly display the response from the react server in state?
Hello everyone, I'm studying react, such a question - I make a request to the server, I get users and organizations for further output through the components, I organized the code in this way. I wanted to know if this is correct? In the future, there will be a user filter by the organization to which it belongs, it turns out the state will change and I think how to organize it all correctly, probably the array with users should be inside the state
class App extends Component {
state = {
loading: true,
selectedOrg: null
};
users = [];
organizations = [];
componentDidMount() {
getUsers()
.then((users) => (this.users = users))
.then(() => getOrganizations())
.then((organizations) => (this.organizations = organizations))
.then(() => this.setState({ loading: false }));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question