Skip to content

Instantly share code, notes, and snippets.

View corsonknowles's full-sized avatar
💭
😇

Dave Corson-Knowles corsonknowles

💭
😇
View GitHub Profile
@corsonknowles
corsonknowles / errorActionCreators.jsx
Created October 4, 2018 20:51
Put this in your Actions folder and import it to all your Redux Action Creators
export const RECEIVE_ERRORS = 'RECEIVE_ERRORS';
export const CLEAR_ERRORS = 'CLEAR_ERRORS';
export const receiveErrors = errors => ({
type: RECEIVE_ERRORS,
errors,
});
export const clearErrors = () => ({
type: CLEAR_ERRORS,
});
@corsonknowles
corsonknowles / errorsReducer.jsx
Created October 4, 2018 20:55
Put this in your Reducers folder and include it in your root reducer with combineReducers();
import { RECEIVE_ERRORS, CLEAR_ERRORS } from '../actions/errorActionCreators';
// Note: Unlike in other reducers, errors are stored in a simple array
const defaultState = () => [];
const ErrorsReducer = (state = defaultState(), action) => {
Object.freeze(state);
switch (action.type) {
case RECEIVE_ERRORS:
return action.errors;
case CLEAR_ERRORS:
return [];
/* eslint-disable no-undef, camelcase */
import ReactOnRails from ‘react-on-rails’;
import { receiveErrors, clearErrors } from ‘./errorActionCreators’;
// protect your Reducers from silently failing by using constants
export const GET_ITEM = 'GET_ITEM';
export const DELETE_ITEM = 'DELETE_ITEM';
export const RECEIVE_ITEMS = 'RECEIVE_ITEMS';