his.props.users || {};
вообще не придется писать.const initialState = {
isLoading,
isError,
users: {},
};
const initialState = {
isLoading,
isError,
usersList: [],
};
this.props.usersList.map(el => { ... }) // точно знаем, что массив есть всегда
const {
reducer,
actions,
selectors,
api,
actionTypes,
} = generateCrudBoilerplate(
'products',
{
getList: () => `/api/products`,
getOne: id => `/api/product/${id}`,
add: payload => `/api/product/`,
remove: id => `/api/product/${id}`,
edit: (id, payload) => `/api/product/${id)`,
}
);
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
function createNamedWrapperReducer(reducerFunction, reducerName) {
return (state, action) => {
const {name} = action;
const isInitializationCall = state === undefined;
if(name !== reducerName && !isInitializationCall) return state;
return reducerFunction(state, action);
}
}
const rootReducer = combineReducers({
counterA : createNamedWrapperReducer(counter, 'A'),
counterB : createNamedWrapperReducer(counter, 'B'),
counterC : createNamedWrapperReducer(counter, 'C'),
});
Правильно переписать, как я посоветовал и использовать так: