问题描述
我第一次使用mobx
和mobx-react-lite
,可以看到@action
没有触发任何事件。
我的意图是当我单击按钮时,名称CHAN应该更改为XIAN。但这没有发生。您能告诉我我做错了什么吗?预先感谢。
解决方法
您在myStore构造函数中缺少struct struct_B{
struct_A *mystructA;
}
struct_B mystructB;
function( (&mystructB)->mystructA ); //this line cause me a segfault
。
makeObservable
,
除了@Christiaan答案外,您还可以使用makeAutoObservable
并完全删除装饰器!
import { observable,action,makeAutoObservable } from "mobx";
export class myStore {
name: string = "CHAN";
constructor() {
makeAutoObservable(this)
}
setName(newName: string) {
this.name = newName;
}
}