Answer the question
In order to leave comments, you need to log in
Why does a reducer throw a ReferenceError?
import { createReducer } from '../storeUtils';
import { SET_PRODUCT_DEPARTMENTS } from '../actions/productActions';
const initialState = {
productDepartments: []
};
function setProductDepartments(state, action) {
return {
...state,
productDepartments: action.payload
};
}
export default createReducer(initialState, {
[SET_PRODUCT_DEPARTMENTS]: setProductDepartments
});
ReferenceError: Cannot access 'SET_PRODUCT_DEPARTMENTS' before initialization
import { SET_PRODUCT_DEPARTMENTS } from '../actions/productActions';
const initialState = {
productDepartments: []
};
const productReducer = (state = initialState, action) => {
switch (action.type) {
case SET_PRODUCT_DEPARTMENTS:
return {
...state,
productDepartments: action.payload
};
default:
return state;
}
};
export default productReducer;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question