Menu

Redux Fetch Resource

Actions


Summary

These are the built in actions which are dispatched with all requests


Reference

Action Types



FETCH_RESOURCE_START


Dispatched before any request starts

Show Example

import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import ReduxFetchResource, {FETCH_RESOURCE_START} from 'redux-fetch-resource';
import reducer from './reducers.js';

const myMiddleware = store => next => action => {
  if (action.type === FETCH_RESOURCE_START) {
    // do something before the request starts
  }

  return next(action);
}

export default createStore(
  reducer,
  applyMiddleware(
    thunk,
    ReduxFetchResource(),
    myMiddleware
  )
);


FETCH_RESOURCE_ERROR


Dispatched on any request/response error

Show Example

import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import ReduxFetchResource, {FETCH_RESOURCE_ERROR} from 'redux-fetch-resource';
import reducer from './reducers.js';

const myMiddleware = store => next => action => {
  if (action.type === FETCH_RESOURCE_ERROR) {
    // do something when an error occurs
  }

  return next(action);
}

export default createStore(
  reducer,
  applyMiddleware(
    thunk,
    ReduxFetchResource(),
    myMiddleware
  )
);


FETCH_RESOURCE_SUCCESS


Dispatched on any successful response

Show Example

import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import ReduxFetchResource, {FETCH_RESOURCE_SUCCESS} from 'redux-fetch-resource';
import reducer from './reducers.js';

const myMiddleware = store => next => action => {
  if (action.type === FETCH_RESOURCE_SUCCESS) {
    // do something when a successful response is received
  }

  return next(action);
}

export default createStore(
  reducer,
  applyMiddleware(
    thunk,
    ReduxFetchResource(),
    myMiddleware
  )
);