Redux Rest Resource
  • Read Me
  • Usage
    • Quickstart
  • Basics
    • Resources
    • Actions
    • Reducers
    • Types
  • Examples
    • Actions
  • Advanced
    • Custom Actions
    • Pure Actions
    • Single Action Helper
    • Headers Override
    • Transform Response
    • Assign Update Response
    • Resource Combination
    • Custom Promise
    • Custom fetch
  • Defaults
    • Actions
    • Headers
    • State
  • Changelog
Powered by GitBook
On this page
  1. Advanced

Pure Actions

You can create pure actions that won't perform any HTTP request and only impact the state.

  • You can configure pure actions with the isPure option, a reduce option must be set:

const url = 'https://foo.com/users/:id';
export const {types, actions, reducers} = createResource({
  name: 'user',
  url,
  actions: {
    clear: {isPure: true, reduce: (state, action) => ({...state, item: null})}
  }
});
  • It will generate the following action creators:

// Action creators available to interact with your REST resource
Object.keys(actions) == ['clearUser'];
  • That will always run your custom reducer

state ==
  {
    item: null
  };
PreviousCustom ActionsNextSingle Action Helper

Last updated 6 years ago