1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| import {observable, action, makeObservable} from 'mobx';
type User = { id: string; token: string; }
class ExampleStore { @observable id = ''; @observable token = ''; @observable user: User; constructor() { makeObservable(this, { token: observable, setToken: action }); makePersistable(this, { name: 'UserStore', properties: ['id', 'token'], storage: window.localStorage, }) .then(() => {}) .catch(() => {}); } @action setToken(token: string) { this.user.token = token } @computed get name(): string { return this.user.firstName + this.user.lastName }
test = computedFn((param) => { return ... }) } export default new ExampleStore()
|