我正在使用lodash
和mobx
来检索数据,看起来像这样:
_.get(store, "prop.arr[0].subProp")
工作正常,但mobx
给我警告arr
是undefined
或空:
Attempt to read an array index (0) that is out of bounds (0). Please check length first. Out of bound indices will not be tracked by MobX
这有什么解决方法吗?我不想添加长度检查,希望将其保持为单行。
在将store
传递给get
之前,请通过mobx通过toJS
实用程序。这应该解决它。
所以你的一个班轮将是 - _.get(toJS(store), "prop.arr[0].subProp")
更多关于toJS
在这里 - https://mobx.js.org/refguide/tojson.html