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

Resource Combination

You can easily combine multiple resources together. For instance, if you want to use children resources attached to a parent store node:

import {createResource} from 'redux-rest-resource';
const hostUrl = 'http://localhost:3000';
// Parent Library Store
const libraryResource = createResource({
  name: 'library',
  pluralName: 'libraries',
  url: `${hostUrl}/libraries/:id`
});
// Children Library Asset Store
const libraryAssetResource = createResource({
  name: 'libraryAsset',
  url: `${hostUrl}/libraries/:libraryId/assets/:id`
});

Exported types and actions do expose unique keys that enables quick and easy merging.

const types = {...libraryResource.types, ...libraryAssetResource.types};
const actions = {...libraryResource.actions, ...libraryAssetResource.actions};

Reducers do require extra care:

import {mergeReducers} from 'redux-rest-resource';
const reducers = mergeReducers(libraryResource.reducers, {assets: libraryAssetResource.reducers});

Finally export an unified resource:

export {types, actions, reducers};
PreviousAssign Update ResponseNextCustom Promise

Last updated 6 years ago