I would like to dispatch a action with String , but the payload
/ tabName
still showing null
in the console.log
in the reducer, can anyone help? Thank you.
Dispatch
store.dispatch(getDetail("new string"));
MapDispatchToProps
function MapDispatchToPropsTab(state) {
return {
getDetail : (tabName) => dispatch(getDetail(tabName)),
}
}
function getDetail(tabName) {
return {
type: 'GET_DETAIL',
payload:tabName
}
}
Reducer
function reducreForTabs(state = initialState4, action) {
if (typeof state === 'undefined') {
return 0
}
switch(action.type) {
case 'GET_DETAIL': {
console.log(action.payload);
var tabs2 = {'title': action.payload};
return {
...state,
tabs: state.tabs.concat(tabs2)
};
}
default :{
return state
}
}
}
答案 0 :(得分:4)
这是一个错字。
function MapDispatchToPropsTab(dispatch) { // not state
return {
getDetail : (tabName) => dispatch(getDetail(tabName)),
}
}