Redux Resource
  • Home
  • Introduction
    • Motivation
    • Core Concepts
    • Similar Projects
    • Examples
  • Resources
    • Resource Reducers
    • Resource Objects
    • Meta
    • Lists
    • Modifying Resources
  • Requests
    • Request Objects
    • Keys
    • Names
    • Statuses
    • Request Actions
      • Updating Lists
      • Reading Resources
      • Updating Resources
      • Creating Resources
      • Deleting Resources
  • Other Guides
    • Usage With React
    • Tracking Request Statuses
    • Using Request Statuses
    • Custom Action Types
    • Migration Guides
  • Recipes
    • Forms
    • Canceling Requests
    • Unauthorized Responses
    • User Feedback
    • Related Resources
    • Caching
  • Ecosystem Extras
    • Redux Resource Action Creators
    • Redux Resource XHR
    • Redux Resource Prop Types
    • Redux Resource Plugins
      • HTTP Status Codes
      • Selection
      • Reset
      • Included Resources
  • FAQ
    • General
    • State Tree
    • Actions
    • Lists
  • API Reference
    • resourceReducer
    • getStatus
    • getResources
    • upsertResources
    • setResourceMeta
    • actionTypes
    • requestStatuses
Powered by GitBook
On this page
  • Arguments
  • Returns
  • Example
  • Tips
  1. API Reference

resourceReducer

PreviousAPI ReferenceNextgetStatus

Last updated 7 years ago

Creates a Redux that manages a .

Arguments

  1. resourceType (String): The type of your resource. Typically, you'll want to use a plural type. For instance, "books," rather than "book." When using , you should also use this as the key of your store slice for consistency.

  2. [options] (Object): Options that can be used to configure the reducer. The options are:

    • initialState: Initial state to shallowly merge into the default initial state for the slice of the store.

    • plugins: An array of reducer functions that will be called after the default reducer function. Use this to augment the behavior of the built-in reducer, or to add support for custom action types for this store slice. Plugins are functions that are called with the arguments (state, action, options), where options are the same options that you passed to resourceReducer. For more, refer to the documentation.

    • initialResourceMeta: Additional metadata to include on any new resource's metadata after a read or create operation.

Returns

(): A reducing function for this resource.

Example

import { createStore, combineReducers } from 'redux';
import { resourceReducer } from 'redux-resource';

let store = createStore(
  combineReducers({
    books: resourceReducer('books'),
    users: resourceReducer('users')
  })
);

Tips

  • Any options you pass to the resourceReducer will also be passed to the

    plugins. You can use this fact to add your own custom options to

    configure the behavior of your plugins. To learn more about plugins, refer

to .

reducer
resource slice
combineReducers
Plugins
Reducer
the Plugins guide