# import

> Note: Currently only works when importing from other `redux-sands`-wrappers. A future release will allow to import any action and state.

`redux-sands` also provides a clean and easy way to import other states and reducers.

## reducer

`import({ reducer: { [wrapperName]: ["reducerName", "reducerName"] }})`

Import other plain reducers by first using the key `reducer`, which holds an object of tuples containing the wrapper's name and an array of the reducer's names.

```javascript
// Example:

import ReduxWrapper from "redux-sands";
import component from "./component";

const wrapper = new ReduxWrapper({ called: "wrapper", component });

wrapper.import({ reducer: { account: ["add", "remove"] }})

// ...
export const saga = wrapper.saga
```

{% hint style="warning" %}
When importing reducers, you have to hook up the saga-export to the saga-middleware in your app. Else the action won't get fired.

If you don't have it installed yet, [here's the project](https://redux-saga.js.org).
{% endhint %}

#### Importing a saga-reducer

When importing a reducer that uses saga, the import changes slightly. Instead of simply using a string to identify the reducer, an object has to be passed to the array containing the reducer-names as `origin` as well as the bool `withSaga` to true.

```javascript
// Example:
// ...

wrapper.import({ reducer: { account: [{ origin: "add", withSaga: true}] }})

// ...
export const saga = wrapper.saga
```

## state

`import({ state: { [wrapperName]: ["stateProp", "stateProp"] }})`

Import oter state props. Works like importing other reducers.

**Renaming**

You're not limited to import them 'as-is'. Every reducer/state-prop can be renamed by simply replacing the string-definition with an object: `{ origin: "originalName", as: "customNameInThisWrapper" }`.

> ```javascript
> // Example:
>
> //... 
>
> wrapper.import({ reducer: {
>   account: [{ origin: "add", as: "addAccount" }, 
>             { origin: "remove", as: "removeAccount" }]
>   }})
> ```
