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
  • Usage
  • resetResource(resourceType, [options])
  • Arguments
  • Returns
  1. Ecosystem Extras
  2. Redux Resource Plugins

Reset

PreviousSelectionNextIncluded Resources

Last updated 7 years ago

The reset plugin allows you to remove all of the data in a slice, effectively "resetting" it. You may optionally scope the resetting to affect a single or .

Usage

First, you need to register this plugin for any slice that needs it.

import { resourceReducer } from 'redux-resource';
import { reset } from 'redux-resource-plugins';

const reducer = resourceReducer('books', {
  plugins: [reset]
});

Then, you can use the action creator that ships with the plugin to perform the reset.

import { reset } from 'redux-resource-plugins';
import store from './store';

store.dispatch(reset.resetResource('books'));

Resetting a slice will leave you with the following state:

{
  resources: {},
  meta: {},
  lists: {},
  requests: {}
}

Resetting a list will set the list to be an empty array.

The additional initial state that you pass to resourceReducer will also be included when you reset your state.

You can pass a second argument, options, to scope what is reset:

import { reset } from 'redux-resource-plugins';
import store from './store';

// Reset just the "createBook" request
store.dispatch(reset.resetResource('books', {
  requestKey: 'createBook'
}));

// Reset just the "favorites" list
store.dispatch(reset.resetResource('books', {
  list: 'favorites'
}));

// Reset a list and a request at the same time
store.dispatch(reset.resetResource('books', {
  list: 'favorites',
  requestKey: 'readFavorites'
}));

resetResource(resourceType, [options])

Resets the slice for resourceType. Pass options to scope what's reset. There are two valid options:

  • requestKey: Reset the request with this key

  • list: Reset the list with this name

Arguments

  1. resourceType (String): The name of the slice to reset.

  2. [options] (String): Options to scope what is reset.

Returns

(Object): A Redux action to be dispatched.

list
request object