# Redux Module

### ReduxModule settings

* [prefix](/rest-redux-module/api/redux-module.md#prefix)
* [defaultState](/rest-redux-module/api/redux-module.md#defaultstate)
* [responseMap](/rest-redux-module/api/redux-module.md#responsemap)

### Actions Props

* [key](/rest-redux-module/api/redux-module.md#key)
* [name](/rest-redux-module/api/redux-module.md#name)
* [idKey](/rest-redux-module/api/redux-module.md#idkey)
* [apiCall](/rest-redux-module/api/redux-module.md#apicall)
* [withoutStatus](/rest-redux-module/api/redux-module.md#withoutstatus)
* [returnResponse](/rest-redux-module/api/redux-module.md#returnresponse)
* [withoutResponse](/rest-redux-module/api/redux-module.md#withoutresponse)
* [alternativeResponse](/rest-redux-module/api/redux-module.md#alternativeresponse)
* [alternativeRequest](/rest-redux-module/api/redux-module.md#alternativerequest)
* [callback](/rest-redux-module/api/redux-module.md#callback)

#### prefix

This prefix will be setted on all actions in this module environment

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| string | Yes      | -             |

#### defaultState

The default data for current state

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| Object | No       | null          |

#### responseMap

This object is for setting the server response.&#x20;

***Default ResponseMapProps***

```javascript
{
  successStatusValue: 'success',
  message: 'message',
  errors: 'errors',
  status: 'status',
  data: 'data',
}
```

For example:

```javascript
// Your server answer is 
const serverResponse = {
    result: [],
    errorData: [],
    response_code: 0,
    messageText: null,
};

// Your responseMap should be
const responseMap = {
    data: 'result',
    errors: 'errorData',
    successStatusValue: 0,
    status: 'response_code',
    message: 'messageText',
}
```

| Type   | Required | Default value     |
| ------ | -------- | ----------------- |
| Object | No       | `RespnseMapProps` |

#### key

The name of the key in which the data will be stored&#x20;

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| string | No       | data          |

#### name

The action name. Default value depends on the action type, for example if you use [`createAddAction`](/rest-redux-module/api/redux-module/createaddaction.md) default value will be `CREATE`

| Type   | Required | Default value         |
| ------ | -------- | --------------------- |
| string | No       | Depends on the action |

#### idKey

This parameter should be used only when using one of this methods createAddAction, createUpdateAction, createDeleteAction . This property is intended to find the desired item by some identifier.&#x20;

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| string | optional | -             |

#### apiCall

This is an API call function, that returns a Promise (required). If you want to update the store without a request to the server you can skip this property. For the store update you need to send data the first argument of the action function.&#x20;

For example

```javascript
// When you not use apiCall property.
const { updateProductAction } = this.props;
const updatedData = { /* some data */ };

updateProductAction(updatedData); // After action the 'updatedData' saved in the store

```

| Type     | Required | Default value |
| -------- | -------- | ------------- |
| function | No       | -             |

#### withoutStatus

When no needed have status parameters.

| Type    | Required | Default value |
| ------- | -------- | ------------- |
| boolean | No       | -             |

#### returnResponse

When the server response have not structure and needed get all response data you can use this property.

| Type    | Required | Default value |
| ------- | -------- | ------------- |
| boolean | No       | -             |

#### withoutResponse

When there is no need to store updates after a request to the server.

| Type    | Required | Default value |
| ------- | -------- | ------------- |
| boolean | No       | -             |

#### alternativeResponse

When need use custom logic for response processing.

| Type     | Required | Default value | Arguments            |
| -------- | -------- | ------------- | -------------------- |
| function | No       | -             | `(response: Object)` |

#### alternativeRequest

When need use custom action or dispatch other actions.&#x20;

```javascript
const alternativeRequest = (dispatch, callFunctionArguments, actionType) => {
// When you will use this function you need remember
// Need use one of this statuses
const STATUS = 'SUCCES' || 'PENDING' || 'ERROR';

dispatch({
    type: `${actionType}_${STATUS}`,
    payload: {}
});
}
```

| Type     | Required | Default value | Arguments                                                                |
| -------- | -------- | ------------- | ------------------------------------------------------------------------ |
| function | No       | -             | `(dispatch: Function, callFunctionArguments: Array, actionType: string)` |

#### callback

When need call function after success response.

| Type     | Required | Default value | Arguments                                |
| -------- | -------- | ------------- | ---------------------------------------- |
| function | No       | -             | `(response: Object, dispatch: Function)` |

### Methods

* [createAction](/rest-redux-module/api/redux-module/createaction.md)
* [createAddAction](/rest-redux-module/api/redux-module/createaddaction.md)
* [createUpdateAction](/rest-redux-module/api/redux-module/createupdateaction.md)
* [createDeleteAction](/rest-redux-module/api/redux-module/createdeleteaction.md)
* [createClearAction](/rest-redux-module/api/redux-module/createclearaction.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://bayazetyan.gitbook.io/rest-redux-module/api/redux-module.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.
