react-redux <provider>缺少动态添加的减速器状态

时间:2019-05-09 10:56:44

标签: react-native redux react-redux

我正在动态地将移除的reducer添加到redux状态,并使用react-redux connect函数将状态映射到prop。我确实添加/删除了减速器,如图所示 https://redux.js.org/recipes/code-splitting使用reducerManager方法。

在代码运行时的某个时刻

...
store.reducerManager.add(campaign.campaignId, UDP.getReducer()); 
console.log('reducer map', store.reducerManager.getReducerMap()); 
return (<UDP campaign={campaign}/>);
....

随后会挂载UDP:

...
const mapStateToProps = (state, ownProps) => {
console.log('[stt]', state)
return({ 
    language:         state.appstate.language,
    currentViewData:  state.appstate.currentViewData,
    currentView:      state.appstate.currentView,
    connectedStampId: state.bluetooth.connectedStampId,
    isBTConnected:  state.bluetooth.isBTConnected,
    isActing:       state[ownProps.campaign.campaignId].isActing, 
})
}
export default connect(mapStateToProps,null,null) (UDP);

问题在于,当mapStateToProps运行时,

state[ownProps.campaign.campaignId] 

是未定义的,而console.log('reducer map'...显示它处于状态。但是传递给mapStateToProps的状态不包含它。

(mapStateToProps也会在第二次运行之后立即运行,然后状态正确)

我不知道我是在做(提供商/ react-redux所不允许的)事情还是做错了事。

0 个答案:

没有答案