redux-simple-fetch
v1.0.5
Published
Redux package for simple fetching data
Downloads
7
Maintainers
Readme
REDUX SIMPLE FETCH
Redux package for simple fetching data with axios
REQUIRED
- installed package redux
- installed package redux-promise-middleware
GET STARTED
Installation
npm install redux-simple-fetch
Info
// Default initial state export const initialState = { result: null, detail: null, postPending: false, getPending: false, getIdPending: false, putPending: false, deletePending: false, getMorePending: false, isError: null, isFinished: false };
Setup project
// Setting reducer import { combineReducers } from 'redux'; import reducerReduxApi from 'redux-api/reducer'; const confReducerReduxApi = reducerReduxApi({ // name reducers contacts: 'CONTACS' }, { // conf reducer propList: 'data', primaryItemField: 'id' }); const appReducers = combineReducers(confReducerReduxApi); export default appReducers;
Usage
import { post, put, delete, get, get_id, get_more } from 'redux-api/action'; ... ... ... dispatch(post('CONTACTS', '/api/v2/contacts')) .then(res => { // the response will be saved in redux and received here }) .catch(err => { // error here }); ... ... ...