Skip to content

Instantly share code, notes, and snippets.

@Ifmr24
Created August 25, 2019 18:15
Show Gist options
  • Save Ifmr24/bceadfbf531668ba3e6b48a38947d0cd to your computer and use it in GitHub Desktop.
Save Ifmr24/bceadfbf531668ba3e6b48a38947d0cd to your computer and use it in GitHub Desktop.
S3 Upload Redux Reducers
import {STARTING_UPLOAD, SUCCESS_UPLOAD, ERROR_UPLOAD} from './actions';
let INITIAL_STATE = {
starting: false,
success: false,
url: null,
error: null
};
export let uploadReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case STARTING_UPLOAD:
return Object.assign({}, state, {
starting: true,
success: false,
url: null,
error: null
});
case SUCCESS_UPLOAD:
return Object.assign({}, state, {
starting: false,
success: true,
url: action.payload,
error: null
});
case ERROR_UPLOAD:
return Object.assign({}, state, {
starting: false,
success: false,
url: null,
error: action.payload
});
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment