Any steps after await aren't in the same tick, so they require action wrapping. Here, we can leverage runInAction:import{ runInAction, makeAutoObservable }from"mobx"classStore{
githubProjects =[]
state ="pending"// "pending", "done" or "error"constructor(){makeAutoObservable(this)}asyncfetchProjects(){this.githubProjects =[]this.state ="pending"try{const projects =awaitfetchGithubProjectsSomehow()const filteredProjects =somePreprocessing(projects)runInAction(()=>{this.githubProjects = filteredProjects
this.state ="done"})}catch(e){runInAction(()=>{this.state ="error"})}}}
mobx使用总结文章目录mobx使用总结一、在mobx监控的组件中,异步情况一、在mobx监控的组件中,异步情况Any steps after await aren't in the same tick, so they require action wrapping. Here, we can leverage runInAction:import { runInAction, makeAutoObservable } from "mobx"class Store { githubP