所以我在我的应用程序中使用了一个普通的 React UI 组件库和 MobX 作为状态管理。当我有一个可观察的数组作为数据并且我想将它从我的组件(它是 a mobx-react
observer
)传递到 UI 库的组件(它的 prop 是 的类型PropTypes.array
)时,组件拒绝它说我的可观察数组是一个对象,而不是数组。
// my store
class Store {
@observable data = [...];
}
// my component
@inject('store')
@observer
class MyComponent extends React.Component {
...
render() {
const {store} = this.props;
return <LibComponent data={store.data} />
}
}
// library's component
class LibComponent extends React.Component {
static propTypes = {
data: PropTypes.array,
....
}
}
我在这个类似的问题中读过关于使用toJS
from mobx 的内容,但是还有其他方法可以解决这个问题吗?由于我不是 UI 库的所有者,因此我无法添加该问题中提到的包中的 PropTypes 验证作为答案。UI 库会对其 prop 的输入做出反应吗?mobx-react
toJS