Reducers
In Redux, reducers are functions in charge of updating the state as new actions happen. They receive the current state and the action (including any payload) and return a new state object. We won't go deep into how reducers work, we just need to understand their basic structure:
/*** src/reducers/index ***/
const initialState = {
images: null,
userImages: null,
error: null,
user: {
id: 78261,
name: 'Sharer1',
pic: 'https://cdn.pixabay.com/photo/2015/07/20/12/53/
man-852762_960_720.jpg'
}
}
export default function (state = initialState, action) {
switch(action.type){
case 'FETCH_IMAGES':
return Object.assign({}, state, {
images: [],
fetchingImages: true,
error: null
});
case 'FETCH_IMAGES_SUCCESS':
return Object.assign({}, state, {
fetchingImages: false,
images: action.images,
error: null
});
case 'FETCH_IMAGES_ERROR':
return Object.assign({}, state, {
...