我正在使用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
)
这似乎是由于未使用的计算机的自动暂停。当表重新呈现时,组件被移除,并且计算的暂时未使用。当它再次使用时,必须再次设置,这涉及调用该功能。
修复是为了确保在此期间在其他地方使用计算,或使用keepAlive
选项。