即使返回的值是同一个对象实例,Mobx @computed也会重复调用

问题描述 投票:0回答:1

我正在使用React Virtualized <Autosizer>组件,我已经验证删除它会导致意外行为消失。

https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md

我的@computed看起来像这样:

foo=[];

@computed get filteredCollection() {
    return this.foo;
}

为什么我看到这种行为?在什么情况下,这个值不会被mobx缓存而只是在不调用函数的情况下返回?

导致意外行为:

<AutoSizer>
    {this.renderTable}
</AutoSizer>

不会导致意外行为:

{this.renderTable({ width: 200, height: 200 })}

filteredCollection使用renderTable

reactjs mobx react-virtualized
1个回答
0
投票

这似乎是由于未使用的计算机的自动暂停。当表重新呈现时,组件被移除,并且计算的暂时未使用。当它再次使用时,必须再次设置,这涉及调用该功能。

修复是为了确保在此期间在其他地方使用计算,或使用keepAlive选项。

© www.soinside.com 2019 - 2024. All rights reserved.