I am using mobx
& mobx-react-lite
for first time and I can see the @action
is not firing any events.
Please find the Code SandBox url here
My intention is when I click on button, the name CHAN should change to XIAN. But it's not happening. Can you please let me know where I made wrong? Thanks in advance.
You are missing the makeObservable
in the myStore constructor.
import { observable, action, makeObservable } from "mobx";
export class myStore {
@observable name: string = "CHAN";
constructor() {
makeObservable(this)
}
@action
setName(newName: string) {
this.name = newName;
}
}