# upsertResources

Add new or update existing resources in your state tree.

## Arguments

1. `resources` *(Object)*: The current resources object from your state tree.
2. `newResources` *(Array|Object)*: The new resources to add or update.
3. \[`mergeResources`] *(Boolean)*: Whether or not to merge individual resources with the existing resource in the store, or to replace it with the new data. Defaults to `true`.

## Returns

(`Object`): The updated resources object.

## Example

```javascript
import { upsertResources } from 'redux-resource';
import actionTypes from './my-action-types';

export default function reducer(state, action) {
  switch (action.type) {
    case (actionTypes.CREATE_RESOURCES_CUSTOM): {
      const newResources = upsertResources({
        resources: state.resources,
        newResources: action.resources
      });

      return {
        ...state,
        resources: newResources
      };
    }
  }
}
```

## Tips

* This is used internally within the reducer returned by

  [`resourceReducer`](/api-reference/resource-reducer.md) to add and update resources in the

  store. You will typically only need to use this function if you're authoring a

  [plugin](/other-guides/custom-action-types.md).


---

# 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/api-reference/upsert-resources.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.
