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

setResourceMeta

Update one or more individual resources with the same metadata.

Arguments

  1. options (Object): An object that defines how to update the metadata. The options are as follows:

    • resources (Array|Object): An array of the resources, or resource IDs, to update with the new meta.

    • newMeta (Object): The meta to set on each of the resources.

    • meta (Object): The current resource meta object from this resource's store slice. Optional when mergeMeta is false, required otherwise.

    • [initialResourceMeta] (Object): Additional metadata to add to any resource that previously did not have meta.

    • [mergeMeta] (Boolean): Whether or not to merge a resource's old metadata with the new metadata. Defaults to true.

Returns

(Object): The new resource meta object.

Example

import { setResourceMeta } from 'redux-resource';
import actionTypes from './my-action-types';

export default function reducer(state, action) {
  switch (action.type) {
    case (actionTypes.SELECT_MANY_RESOURCES): {
      const meta = setResourceMeta({
        resources: action.resources,
        meta: state.meta,
        newMeta: {
          selected: true
        }
      });

      return {
        ...state,
        meta
      };
    }
  }
}

Tips

  • This is used internally within the reducer returned by

    state tree. You will typically only need to use this method if you're writing

PreviousupsertResourcesNextactionTypes

Last updated 7 years ago

to update the resource meta in your

a .

resourceReducer
plugin