# getMutableReducer

### Prerequisites

{% hint style="warning" %}
Please read about [createDuck](/ngrx-ducks/ngrx-ducks-core/architecture/createduck.md) first before continue here. You nee a basic understanding about its API first.
{% endhint %}

### Generate a mutable reducer

The method `getMutableReducer` takes care about connecting your case-reducer functions with immer and finally builds a reducer function that can be registered in the Store.

{% tabs %}
{% tab title="chunk.ts" %}

```typescript
import { getMutableReducer, createMutableDuck } from '@ngrx-ducks/core';

@StoreChunk()
export class Chunk {
  static reducer = getMutableReducer(initialState, CounterMutableFacade);
  
  // Basic usage without case reducer
  // loadCount = createMutableDuck(
  //   '[Counter] Load Count',
  //   dispatch<number>()
  // );

  // Usage with a case reducer
  // increment = createMutableDuck(
  //   '[Counter] Increment value',
  //   (state: CounterState, payload: number) => (state.count += payload)
  // );
}
```

{% endtab %}

{% tab title="index.ts" %}

```typescript
import { Action, combineReducers } from '@ngrx/store';
import { MutableFacade } from './facade';
import { CounterState } from './counter.state';

export interface State {
  couter: CounterState;
}

export function reducers(state: State, action: Action) {
  return combineReducers<State>({
    couter: MutableFacade.reducer
  })(state, action);
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You will find a full example of a mutable facade at [StackBlitz](https://stackblitz.com/edit/ngrx-ducks-12?file=src%2Fapp%2Fcounter%2Fstore%2Fcounter%2Fcounter-mutable.facade.ts).
{% endhint %}


---

# 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://co-it.gitbook.io/ngrx-ducks/ngrx-ducks-core/architecture/getmutablereducer.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.
