Reputation: 171
MobX 6 sees the 'counter' variable in a react project I set up. But it doesn't see functions(increment, decrement). I have attached the output to the attached picture. What would be the reason?
import {observable, computed, action, makeObservable} from 'mobx';
class UserStore {
counter = 0;
increment() {
this.counter++;
}
decrement() {
this.counter--;
}
get counterMoreThan10() {
return this.counter > 10;
}
constructor() {
console.log('constructor')
makeObservable(this, {
counter: observable,
increment: action,
decrement: action,
counterMoreThan10: computed
});
}
}
const store = new UserStore();
export default store;
import React from 'react';
import {inject, observer} from "mobx-react";
const Dashboard = ({UserStore}) => {
console.log(UserStore)
return(
<>
</>
)
}
export default inject('UserStore')(observer(Dashboard));
Upvotes: 0
Views: 278
Reputation: 18566
Have you checked prototype __proto__
?
MobX might (or might not, it is implementation detail) create proxy class to hold methods or other stuff.
Try to do console.log(UserStore.__proto__)
or just console.log(UserStore.increment)
Upvotes: 1