# Reset

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 [list](/resources/lists.md) or [request object](/requests/request-objects.md).

## Usage

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

```javascript
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.

```javascript
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:

```javascript
{
  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:

```javascript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redux-resource.js.org/extras/redux-resource-plugins/reset-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
