-
-
Save indigoviolet/8f1930ef3d7264e4db4812200b8b6bb6 to your computer and use it in GitHub Desktop.
fin blog embed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helpers/async.js | |
import { combineReducers } from 'redux'; | |
export const createAsyncReducer = (type) => { | |
const loading = (state = false, action) => { | |
if (action.type === type) { | |
return action.readyState === REQUEST; | |
} | |
return state; | |
}; | |
const data = (state = null, action) => { | |
if (action.type === type) { | |
return action.data; | |
} | |
return state; | |
}; | |
const error = (state = null, action) => { | |
if (action.type === type) { | |
return action.error; | |
} | |
return state; | |
}; | |
return combineReducers({ loading, data, error }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment