Skip to content

setState not being called. #6178

@robskidmore

Description

@robskidmore

After an API call setState is not being triggered. The first console.log statement works as expected and displays all the empty objects from my constructor function, but the callback to setState is never triggered and state is not updated. I've let it sit like this for over 10min.

I have no console errors.

The strange part is that when I am working in another part of the app it magically begins working again and I have no idea why. Am I missing something obvious?

componentDidMount() {
    this.init()
}

init() {
    getDashboard()
        .then(function(data) {
            console.log(this.state)
            this.setState({
                dashboard: data.dashboard,
                learning: data.learning,
                items: data.items
            }, () => {console.log(this.state)})
        }.bind(this))
}

I get the same result when I remove the second console.log() from the setState callback and simply place it directly after it.

console.log(this.state)
this.setState({
    dashboard: data.dashboard,
    learning: data.learning,
    items: data.items
})
console.log(this.state)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions