> For the complete documentation index, see [llms.txt](https://redux-resource.js.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redux-resource.js.org/api-reference/get-resources.md).

# getResources

Returns an array or object of resources from `resourceSlice` based on the `filter` provided.

### Arguments

1. `resourceSlice` *(Object)*: The slice of your state that a `resourceReducer` is responsible for.
2. `filter` *(Array|String|Function)*: The filter to apply. It can be an array of resource IDs, or the name of a [list](/resources/lists.md). If a function is provided, then `getResources` will iterate over the collection of resources, returning the resources that the function returns truthy for. The function will be called with three arguments: `(resource, resourceMeta, resourceSlice)`. If no `filter` is provided, then all of the resources in the `resourceSlice` will be returned.
3. `options` *(Object)*: An object to customize the behavior of `getResources`. Presently, only one option is supported: `byId`. Pass `{ byId true }` to receive the results as an object instead of an array.

### Returns

(*`Array|Object`*): An Array of resources, unless `byId` is passed as true, in which case an object will be returned instead.

### Example

```javascript
import { getResources } from 'redux-resource';
import store from './store';

const state = store.getState();

// Retrieve resources by an array of IDs
const someBooks = getResources(state.books, [1, 12, 23]);

// Retrieve those same resources as an object
const someBooksAsObject = getResources(state.books, [1, 12, 23], { byId: true });

// Retrieve resources by a list name
const popularBooks = getResources(state.books, 'mostPopular');

// Retrieve the "selected" resources
const selectedBooks = getResources(state.books, (resource, meta) => meta.selected);

// Returns all resources
const allResources = getResources(state.books);
```

## Tips

* You don't *always* need to use this method to access resources. Just need one resource? If the resource is on a slice called `books`, you can directly access it using `store.getState().books.resources[bookId]`.
* When the order of your resources doesn't matter, then it probably makes sense to pass `{ byId: true }` as `options` so that you can look up your resources more quickly.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://redux-resource.js.org/api-reference/get-resources.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
