A
A
Alexandra2020-11-25 09:01:16
JavaScript
Alexandra, 2020-11-25 09:01:16

Why is the value not written to state?

I receive data from the server and try to write to the state, but nothing happens

state = {
    loading: true,
    selectOrg: null,
    users: []
}

componentDidMount() {
    const users1 = []
    getUsers()
        .then(users => (this.users1 = users))
        .then(() => this.setState({
            loading: false,
            users: users1,
            orgs: orgs
        }))
        .then(() => {
            console.log(this.users1) // [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] тут все норм
            console.log(this.state.loading) // false тут норм
            console.log(this.state.users) // [] а в state пусто ...
        });
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question