Answer the question
In order to leave comments, you need to log in
Why asynchronous request fails?
1. I am learning to process asynchronous requests, I catch "items.map is not a function". What's the matter and how to fix it? My code:
https://codesandbox.io/s/vj2m955q37
2. In pursuit. How to make items received from the server not overwrite items from initialState, but join them?
3. When and what arrow function syntax to use?
export const fetchProductsBegin = () => ({
type: FETCH_BEGIN
});
export const fetchBegin = () => {
return {
type: "FETCH_BEGIN"
};
}
Answer the question
In order to leave comments, you need to log in
1. Fix mapStateToProps :
const mapStateToProps = state => {
return {
items: state.items.items,
error: state.items.error,
loading: state.items.loading
};
};
export function items(state = initialState, action) {
const { type, payload } = action;
switch (type) {
// some code
case "FETCH_SUCCESS":
return {
...state,
items: [ ...state.items, ...payload.items ],
loading: false,
};
// some code
}
}
export const fetchProductsBegin = () => ({ type: FETCH_BEGIN });
const mapStateToProps = state => ({
items: state.items.items,
error: state.items.error,
loading: state.items.loading,
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question