componentDidMount() {
this.props.fetchData();
window.addEventListener('scroll', this.handleScroll);
};
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
};
handleScroll() {
this.props.fetchData()
};
export function items(state = [], action) {
switch (action.type) {
case 'ITEMS':
return action.items;
default:
return state;
}
}
const initialState = {
limit: 20,
page: 1,
data: [],
isFetching: false,
isFail: false,
};
export function items(state = initialState, action) {
switch (action.type) {
case 'FETCH_ITEMS':
return { ...state, isFetching: true, isFail: false };
case 'FETCH_ITEMS_SUCCESS':
return {
...state,
isFetching: false,
data: [ ...state.data, ...action.payload.data ],
page: action.payload.page,
};
case 'FETCH_ITEMS_FAIL':
return { ...state, isFetching: false, isFail: true };
default:
return state;
}
}