国家在哪里有问题
mapDispatchToProps
似乎正在更新,但组件不会重新渲染以反映这些更改,即使。。。
const initialState = {
session: {
...
toUpdate: {success: false, processing: false, message: ''},
...
},
someOtherStateSections: {...},
...
}
const sessionReducer = (state=initialState.session, action) => {
switch (action.type) {
...
case Types.ACTION_TO_HANDLE:
console.log(`REDUCER: ACTION_TO_HANDLE: check that state is being updating with intended values:\n${JSON.stringify(action, null, 2)}`)
return Object.assign({}, state, {toUpdate: {
success: action.success,
processing: action.processing,
message: action.message,
}})
...
}
}
const rootReducer = combineReducers({
session: sessionReducer,
...
})
export default rootReducer;
-
从reducer更新后,日志语句似乎显示
state
阿格。在
mapStateToProps
功能正在更新以反映这些更改。代码片段看起来像
const mapStateToProps = (state, ownProps) => {
console.log(`PickupLocationAnchorFormContainer: mapStateToProps: ${JSON.stringify(state.session.pickupLocationAnchorChangeStatus, null, 2)}`)
return {
toUpdate: state.session.toUpdate,
ownProps: ownProps,
}
}
const mapDispatchToProps = (dispatch,) => {
return {
someThunk: (some, inputs) => {
dispatch(someThunk(some, inputs))
},
}
}
const MyComponentContainer = connect(
mapStateToProps,
mapDispatchToProps
)(MyComponent)
export default MyComponentContainer
然而
MyComponent
似乎没有更新其
this.props.toUpdate
以获取更新的redux存储值。
如有任何进一步的调试建议或推荐的解决方案,将不胜感激。