react引用Model / Dialog组件报错,提示store没有挂载到Provider组件上。

我们来回顾下store的挂载过程

我们通过Provider组件把store挂载到App组件上,App内的所有子组件都可以通过mapStateToProps、mapDispatchToProps两方法直接访问、操作store。
我们再来看下Dialog的使用方式

我们引用一般组件,是把组件写在App内,而Dialog组件的调用方式要通过openDialog方法,Dialog组件不是App的子组件,所以Dialog组件是不能直接访问、操作挂载到App组件上的store的。

【注意】使用Dialog、Model组件需要再次挂载Provider

网友评论