mobx computed always update that computed 不起作用

mobx computed always update that computed doesn't work

import {makeAutoObservable} from "mobx";

class Test {
    id = 0
    constructor() {
        makeAutoObservable(this)
    }

    get total() {
        console.log('enss')
        return 2;
    }
}

const store = new Test();
export default store;

通话:

import {isComputed, isComputedProp} from "mobx";

console.log(isComputedProp(Test, 'total'),Test.total,Test.total, Test.total, isComputedProp(Test, 'total'))

控制台输出: 恩斯 恩斯 恩斯 真 2 2 2 真

计算的没有工作,不作为缓存。 我在 React 18 中使用 mobx 6.6 版本。

非常感谢您的回答!

这在文档中有解释 here

It sometimes confuses people new to MobX, perhaps used to a library like Reselect, that if you create a computed property but don't use it anywhere in a reaction, it is not memoized and appears to be recomputed more often than necessary. For example, if we extended the above example with calling console.log(order.total) twice, after we called stop(), the value would be recomputed twice.

如果你在反应上下文之外使用它,基本上它不会被缓存。

您可以使用 computed({ keepAlive: true }) 选项来更改此行为