how can i update the state with mobx hooks async code example
Example: mobx react hooks async
mobx.configure({ enforceActions: "observed" })
class Store {
@observable githubProjects = []
@observable state = "pending"
@action
fetchProjects() {
this.githubProjects = []
this.state = "pending"
fetchGithubProjectsSomehow().then(this.fetchProjectsSuccess, this.fetchProjectsError)
}
@action.bound
fetchProjectsSuccess(projects) {
const filteredProjects = somePreprocessing(projects)
this.githubProjects = filteredProjects
this.state = "done"
}
@action.bound
fetchProjectsError(error) {
this.state = "error"
}
}